From 341e25ed60695fc0aef672029ea6d17cbefe8376 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 00:49:38 +0000 Subject: [PATCH 01/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..34dcc1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( 'null3J', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index b9aff68..52a1ddf 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.0.2", "@stdlib/ndarray-base-buffer": "^0.0.6", "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 1059cf6312a8197098cd56a4139aefd4a58e9e1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 00:51:19 +0000 Subject: [PATCH 02/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 39 +- benchmark/benchmark.js | 265 - branches.md | 53 - docs/repl.txt | 41 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 339 -- 36 files changed, 6201 insertions(+), 4122 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f3744e6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e05cfd9..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -147,7 +140,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -207,9 +200,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c55639e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,41 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 300971b..41bb80d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ComplexLike } from '@stdlib/types/object'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..53d103b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.0.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..54aae0a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;yoBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 24525ab..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray to a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 34dcc1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'null3J', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 52a1ddf..0c38156 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast a scalar value to an ndarray to a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-setter": "^0.0.1", - "@stdlib/array-base-zeros": "^0.0.2", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..43c005e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From c65a5244ace2b060584b91b88ce5329220a44621 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 00:58:15 +0000 Subject: [PATCH 03/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..34dcc1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( 'null3J', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index cef2d35..88c7afb 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.0.2", "@stdlib/ndarray-base-buffer": "^0.0.6", "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From c20db8f8b0eb342971d4f50a7662b43410f7f19a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 00:58:49 +0000 Subject: [PATCH 04/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 41bb80d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ComplexLike } from '@stdlib/types/object'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 53d103b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.0.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 54aae0a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;yoBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 43c005e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 32a83abc6cda0bd6b6dfcaf76d1766f447816376 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 00:59:36 +0000 Subject: [PATCH 05/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 39 +- benchmark/benchmark.js | 265 - branches.md | 53 - docs/repl.txt | 41 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 339 -- 36 files changed, 6201 insertions(+), 4122 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f3744e6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e05cfd9..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -147,7 +140,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -207,9 +200,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c55639e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,41 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 300971b..41bb80d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ComplexLike } from '@stdlib/types/object'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dfbad74 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fd5d1f7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;onBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 34dcc1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'null3J', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 88c7afb..434477e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-setter": "^0.0.1", - "@stdlib/array-base-zeros": "^0.0.2", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a510413 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 462f8c1ea126921f57f75ae424c5930cc2d2c980 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 01:00:20 +0000 Subject: [PATCH 06/95] Update README.md for ESM bundle v0.0.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69b6bc8..ce4f581 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.0.0-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -93,7 +93,7 @@ var v = x.get( 0, 0 ); - - - - From d1f161aaff2836163d58cedcd8c84750a9013c3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 24 Mar 2023 01:06:47 +0000 Subject: [PATCH 10/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 339 -- 36 files changed, 6202 insertions(+), 4135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f3744e6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e05cfd9..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -149,7 +142,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -209,11 +202,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 300971b..41bb80d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ComplexLike } from '@stdlib/types/object'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..53d103b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.0.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..54aae0a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;yoBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 34dcc1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'null3J', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 88c7afb..434477e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-setter": "^0.0.1", - "@stdlib/array-base-zeros": "^0.0.2", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5164ad8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 1fe9ec09c88939fd8da4b27fceb9b3c8734d2579 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Jul 2023 15:23:19 +0000 Subject: [PATCH 11/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..34dcc1d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( 'null3J', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 5f409a2..4d32f25 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.0.2", "@stdlib/ndarray-base-buffer": "^0.0.6", "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 43f8661366ca36bb71ff2137a14f36263698d3aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Jul 2023 15:23:50 +0000 Subject: [PATCH 12/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 41bb80d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ComplexLike } from '@stdlib/types/object'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 53d103b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.0.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 54aae0a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;yoBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5164ad8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 19a30340779f40d5d26b3988b50c75ac973b185b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Jul 2023 15:24:43 +0000 Subject: [PATCH 13/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 339 -- 36 files changed, 6202 insertions(+), 4135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f3744e6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e05cfd9..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -149,7 +142,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -209,11 +202,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 300971b..41bb80d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ComplexLike } from '@stdlib/types/object'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..53d103b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.0.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(i,o,a,l){var j;if(null===(j=d(o,1)))throw new TypeError(n("null3J",o));return/^complex/.test(o)&&"number"==typeof i&&(i=[i,0]),(s(j)?r(o):e(o))(j,0,i),new m(o,j,a,t(a.length),0,l)}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..54aae0a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'null3J', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;yoBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,SAAUN,IAWxC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 34dcc1d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'null3J', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 4d32f25..e42cf3d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-setter": "^0.0.1", - "@stdlib/array-base-zeros": "^0.0.2", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-ctor": "^0.0.6", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9cf6034 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 4a813b02d94211132d32baf7c1b58058e17843e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 31 Jul 2023 15:25:36 +0000 Subject: [PATCH 14/95] Update README.md for ESM bundle v0.0.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9177078..98bb927 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.0.1-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -95,7 +95,7 @@ var v = x.get( 0, 0 ); - - - - From 95805525ba00d4964b6450f10968e11bef032068 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 16:15:08 +0000 Subject: [PATCH 18/95] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 339 -- 40 files changed, 6202 insertions(+), 4170 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index f3744e6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index e05cfd9..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 713fa2c..46ab832 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..193d16d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..820898a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;upBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 04d6f32..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9dcef8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From fc1222b7eb0fed8c0526aae00246e93e5b93ae66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 16:23:09 +0000 Subject: [PATCH 19/95] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1872255..c083579 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.1.0-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -106,7 +106,7 @@ var v = x.get( 0, 0 ); - - - - From 4ba2299073f1a4ec8710bb27f29c5d8eba966ef0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 01:33:04 +0000 Subject: [PATCH 23/95] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 339 -- test/test.js | 339 -- 42 files changed, 6202 insertions(+), 4568 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0747bd2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:16:47.427Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4123808..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 713fa2c..46ab832 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a10b53d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8903535 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index dab2574..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..018dad8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index bc61b39..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 0cf81c0297d6fa8d2a463cd6c50dea5b4fb7891c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 19:40:01 +0000 Subject: [PATCH 24/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..2e1ea9c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337,L0', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index ac421fa..907f901 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From e3f9c5f3776ef38f3a7704696ef3a544f43089e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:51:34 +0000 Subject: [PATCH 25/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 46ab832..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a10b53d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8903535..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 018dad8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 06016c3c90a17c4f66e546b6e6f0df42c5562bc1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:52:41 +0000 Subject: [PATCH 26/95] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 339 -- test/test.js | 339 -- 41 files changed, 6202 insertions(+), 4567 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4123808..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 713fa2c..46ab832 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e4b81a3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8903535 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 907f901..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e80cb33 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index bc61b39..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From a189b71b298cb42af8ee5b385280247d204c33bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:21:13 +0000 Subject: [PATCH 27/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..2e1ea9c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337,L0', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 8d78d86..5340eba 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d70c66eaefd6673e4f1e3d931652f75abf42196a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:50:51 +0000 Subject: [PATCH 28/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 46ab832..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e4b81a3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8903535..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e80cb33..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 000c1930ac997fd081fb42e7478255b2906d4922 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:52:01 +0000 Subject: [PATCH 29/95] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 6202 insertions(+), 4270 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 57ff6b9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:36:22.391Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4123808..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 713fa2c..46ab832 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e4b81a3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8903535 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5340eba..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97f23cc --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 0f573fd69638cacc2a7bfe5001e22a0176347b27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 11:20:36 +0000 Subject: [PATCH 30/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..2e1ea9c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337,L0', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 794501c..d72033d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 6b2bd0c8e1b577ad66eefd0a4da3eaa441248026 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:33:57 +0000 Subject: [PATCH 31/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 46ab832..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; // tslint:disable-line:max-line-length - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e4b81a3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8903535..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97f23cc..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c64d19c024082c799b5a12f3414c945e9ba4f332 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:35:08 +0000 Subject: [PATCH 32/95] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 41 files changed, 6202 insertions(+), 4269 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4123808..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d45f964..8ef11fe 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e4b81a3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8903535 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index d72033d..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b396b3b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From ff067153333e1611a7ec8c7d5c10e88a8206dc9c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:31:07 +0000 Subject: [PATCH 33/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..2e1ea9c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337,L0', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 340d516..0f43410 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 51be2797cf23a4d54152355034c1b5898cdb7360 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:40:42 +0000 Subject: [PATCH 34/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 8ef11fe..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e4b81a3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8903535..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b396b3b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f80d8b5cf526bb2bf53bf2f2a3e507151436b213 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:41:17 +0000 Subject: [PATCH 35/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 6202 insertions(+), 4265 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8f17a4c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:41:46.366Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 4123808..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index e96eec5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d45f964..8ef11fe 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e4b81a3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8903535 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2e1ea9c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337,L0', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 0f43410..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..abd8d3f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 12a810e0aa29fa29a752a122705e9d7e4149284a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:02:54 +0000 Subject: [PATCH 36/95] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a83775d..ee70407 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 006bb0ccefc1e4cebe915a7aa2fc07df1f62c6b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:43:15 +0000 Subject: [PATCH 37/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 8ef11fe..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e4b81a3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337,L0",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8903535..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337,L0', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,WAAYN,IAW1C,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index abd8d3f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 04cdb979b912d176f8c1e914cc49195cf6b53be2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:43:41 +0000 Subject: [PATCH 38/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 6202 insertions(+), 4271 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4697017..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:11:02.022Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3934a24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 31870fb..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d45f964..8ef11fe 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2f113e0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(a,m,o,j){var l;if(null===(l=n(m,1)))throw new TypeError(i("invalid argument. Second argument must be a recognized data type. Value: `%s`.",m));return/^complex/.test(m)&&"number"==typeof a&&(a=[a,0]),(s(l)?e(m):r(m))(l,0,a),new d(m,l,o,t(o.length),0,j)}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..058d592 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;4pBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,iFAAkFN,IAWhH,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d7d3aa2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index ee70407..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..863a382 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From d9e3092357097796bef0b5d03f8b0c52121177e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:36:20 +0000 Subject: [PATCH 39/95] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a83775d..ee70407 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.1.1", "@stdlib/ndarray-base-buffer": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 17d546aa3fe41a8ba09ff18d37eb6607f33eb4a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:01:13 +0000 Subject: [PATCH 40/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 8ef11fe..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( `@stdlib/complex/float64` ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( `@stdlib/complex/float32` ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2f113e0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(a,m,o,j){var l;if(null===(l=n(m,1)))throw new TypeError(i("invalid argument. Second argument must be a recognized data type. Value: `%s`.",m));return/^complex/.test(m)&&"number"==typeof a&&(a=[a,0]),(s(l)?e(m):r(m))(l,0,a),new d(m,l,o,t(o.length),0,j)}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 058d592..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;4pBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,iFAAkFN,IAWhH,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 863a382..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c4993092750b5327ccecddd9d34b4a062edbcb15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:01:30 +0000 Subject: [PATCH 41/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 6202 insertions(+), 4276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e26855d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:01:08.076Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3934a24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2f113e0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(a,m,o,j){var l;if(null===(l=n(m,1)))throw new TypeError(i("invalid argument. Second argument must be a recognized data type. Value: `%s`.",m));return/^complex/.test(m)&&"number"==typeof a&&(a=[a,0]),(s(l)?e(m):r(m))(l,0,a),new d(m,l,o,t(o.length),0,j)}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..058d592 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;4pBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,iFAAkFN,IAWhH,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d7d3aa2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index ee70407..efcf059 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-setter": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a4be7d9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 7d5ee1dd38ece65cf7b527bde00d914d02a2af6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:19:16 +0000 Subject: [PATCH 42/95] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3e56bc..5c3aa1f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.0", "@stdlib/ndarray-base-buffer": "^0.2.0", "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From ecebf5edf5532dbe101058733e1436f35228d950 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:16:41 +0000 Subject: [PATCH 43/95] Remove files --- index.d.ts | 349 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6531 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45b0b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64' ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2f113e0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(a,m,o,j){var l;if(null===(l=n(m,1)))throw new TypeError(i("invalid argument. Second argument must be a recognized data type. Value: `%s`.",m));return/^complex/.test(m)&&"number"==typeof a&&(a=[a,0]),(s(l)?e(m):r(m))(l,0,a),new d(m,l,o,t(o.length),0,j)}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 058d592..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;4pBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,iFAAkFN,IAWhH,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a4be7d9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fd707f7c40af935db6b75b14e306bcb3cd8e61fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:17:04 +0000 Subject: [PATCH 44/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 6202 insertions(+), 4279 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 670b71c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58dd01c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(a,m,o,j){var l;if(null===(l=n(m,1)))throw new TypeError(i("invalid argument. Second argument must be a recognized data type. Value: `%s`.",m));return/^complex/.test(m)&&"number"==typeof a&&(a=[a,0]),(s(l)?e(m):r(m))(l,0,a),new d(m,l,o,t(o.length),0,j)}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..058d592 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;4pBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,iFAAkFN,IAWhH,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d7d3aa2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5c3aa1f..acafe4b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-setter": "^0.2.0", - "@stdlib/array-base-zeros": "^0.2.0", - "@stdlib/ndarray-base-buffer": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.2.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int16": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-int8": "^0.2.0", - "@stdlib/array-uint16": "^0.2.0", - "@stdlib/array-uint32": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/array-uint8c": "^0.2.0", - "@stdlib/assert-instance-of": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/complex-float32": "^0.2.0", - "@stdlib/complex-float64": "^0.2.0", - "@stdlib/ndarray-dtypes": "^0.2.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01d02c6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From d3efe82aba0167afd7cbaf5193e44fa1d041842e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:58:30 +0000 Subject: [PATCH 45/95] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c62d75..160ef3e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.0-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -106,7 +106,7 @@ var v = x.get( 0, 0 ); - - - - From 3b53c4d11d33645cc8ca9725cb34bd49359c00f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:10:38 +0000 Subject: [PATCH 49/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 4867 insertions(+), 4274 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87b4a08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index e47e07a..472c8ac 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.0", - "@stdlib/array-complex64": "^0.2.0", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..61644e3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 9afe259beb7a4c6f496426f983f3cfbfe92ee4aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:49:20 +0000 Subject: [PATCH 50/95] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b464f5..a36fdfd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.1-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -106,7 +106,7 @@ var v = x.get( 0, 0 ); - - - - From 02823397ebcc8c965238c68b83e9b3344fb54af5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:39:29 +0000 Subject: [PATCH 54/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4276 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ddc384b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:43:02.118Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87b4a08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 499ed85..472c8ac 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..61644e3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 48c62a137c24f33ecf9dd86eb02ad0b723c4b354 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:13:05 +0000 Subject: [PATCH 55/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 805869a..499ed85 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.1", "@stdlib/ndarray-base-buffer": "^0.2.1", "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 493654e85748ba5c5bff2cef05dfbb085b26fe3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:39:54 +0000 Subject: [PATCH 56/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45b0b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64' ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87b4a08..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 61644e3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 55dbb5762c3c1fe07a976b2e8090e1d99947a0d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:40:06 +0000 Subject: [PATCH 57/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4279 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4065306..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:01:02.257Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87b4a08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 499ed85..472c8ac 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..61644e3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 728048b40cf8c76f3bdf3201b9d9acf1dbb561ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:30:38 +0000 Subject: [PATCH 58/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 805869a..499ed85 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.1", "@stdlib/ndarray-base-buffer": "^0.2.1", "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From b30e9fbd90518b4a25517e3b3ddbd3e6d18ef1f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:55:35 +0000 Subject: [PATCH 59/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45b0b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64' ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87b4a08..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 61644e3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 772dce7aa227849be54d43f04034fb526eb032bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:55:50 +0000 Subject: [PATCH 60/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 4867 insertions(+), 4280 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 511d089..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6afa15c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){ -var c=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/array-base-accessor-setter/dist'),q=require('@stdlib/array-base-setter/dist'),v=require('@stdlib/array-base-zeros/dist'),m=require('@stdlib/ndarray-base-buffer/dist'),b=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l('1d337',r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g -});var w=u();module.exports=w; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 8caaa9a..45b0b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..87b4a08 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 499ed85..472c8ac 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..61644e3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4c3dddc..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From d273a95a70bae35b4ca0a1e9d6dcf1ef3b1b0963 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:49:11 +0000 Subject: [PATCH 61/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 2c3ce49..b1b1916 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.2.1", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 3a7e822bb4562260c5829cd2a970f5102dff5f63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:00:59 +0000 Subject: [PATCH 62/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 45b0b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64' ); -* var real = require( '@stdlib/complex-real' ); -* var imag = require( '@stdlib/complex-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 87b4a08..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 61644e3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 95b84613caefbf011eafd15e22760cb897d26f07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:01:18 +0000 Subject: [PATCH 63/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 204 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 4867 insertions(+), 4506 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index b1b1916..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 662ce143bbcb6b778814013a13ac9f87d2ceb340 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:10:07 +0000 Subject: [PATCH 64/95] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 516e8a2..162a8d2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs'; +import broadcastScalar from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs'; ``` #### broadcastScalar( value, dtype, shape, order ) @@ -106,7 +106,7 @@ var v = x.get( 0, 0 ); - - - - From b92191c13779362d06eb4f6d3942a75422179fb6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:57:57 +0000 Subject: [PATCH 68/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 88 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4391 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e867a13..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:53:43.698Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index e81fa29..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From d44f2c9b1f8ff0b38a2b3d8cd3c6ebc0bd42ffc5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:26:04 +0000 Subject: [PATCH 69/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 28fe912..5568500 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 97fef5bd3712d503b2ea96208db72bc29af58bd2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:54:45 +0000 Subject: [PATCH 70/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4c733ae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4615bf9c905810cf7fcdc1afbd11b3d35fce5e19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:55:00 +0000 Subject: [PATCH 71/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 203 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4506 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ed13cf3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:20:33.968Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5568500..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 0a8541751f713cdc1adee978648ac84388b3196a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Sep 2024 14:24:03 +0000 Subject: [PATCH 72/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 28fe912..5568500 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 357576d4dd43ab5a6714058753d1612020a7d675 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Sep 2024 14:49:13 +0000 Subject: [PATCH 73/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4c733ae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ccf5d0ec8c46da28cd079f9647f0ffa039adfaad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 17 Sep 2024 14:49:38 +0000 Subject: [PATCH 74/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 237 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 42 files changed, 4867 insertions(+), 4539 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5568500..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From f68d714629552ba6b1d453b67748516fb1ae36b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:43:44 +0000 Subject: [PATCH 75/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 28fe912..5568500 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From a048dd1e527281bef6973c992d511c8abca2c171 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:24:40 +0000 Subject: [PATCH 76/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4c733ae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5ca620fb104b3a5abac1fb942105d2e014780ed6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:24:55 +0000 Subject: [PATCH 77/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 237 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4540 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 21a9dcb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:32:40.840Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5568500..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From c8694f61908cd7bd4a4d3e5ac68a53e028cabdd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:29:49 +0000 Subject: [PATCH 78/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 28fe912..5568500 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 8d08cd6e30565418195920217e31a5d01e3f49f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:31:59 +0000 Subject: [PATCH 79/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4c733ae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e26bd32b7999af1802dfd7f440b16e5ff64e9e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:32:15 +0000 Subject: [PATCH 80/95] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 237 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4540 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ace8385..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:35:52.309Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a8da57a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4c733ae --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 5568500..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 95a4a0c023fa8ea7f5183717c15b25da70747fcf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:48:28 +0000 Subject: [PATCH 81/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index d7d3aa2..3d682cc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -60,7 +60,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && typeof value === 'number' ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 6fd3c78..8ee709e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-base-zeros": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 908da6de2c8dfe7019ccc247c5c8bb7a608ef1c0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:11:05 +0000 Subject: [PATCH 82/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4c733ae..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3db76fd2aaab98be83bda21f6d1967226d32b5e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:11:22 +0000 Subject: [PATCH 83/95] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 237 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 44 files changed, 4867 insertions(+), 4648 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 925ef0a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-17T01:42:49.297Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21e46b9..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0bba5ea..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(S,s){"use strict";var c=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),q=require("@stdlib/array-base-setter"),v=require("@stdlib/array-base-zeros"),m=require("@stdlib/ndarray-base-buffer"),b=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/string-format");function g(e,r,i,n){var a,t;if(a=m(r,1),a===null)throw new TypeError(l("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&typeof e=="number"&&(e=[e,0]),c(a)?t=f(r):t=q(r),t(a,0,e),new b(r,a,i,v(i.length),0,n)}s.exports=g});var w=u();module.exports=w; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index bcd8b9c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAK,OAAOD,GAAU,WACjDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAZ,EAAO,QAAUQ,ICpCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bd8ff22 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..12f2188 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3d682cc..0000000 --- a/lib/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && typeof value === 'number' ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 8ee709e..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9a924ce --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 3d7bb017a1d4cfdaefe8f477e88e4b153a5f2ff7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 23 Mar 2025 11:19:22 +0000 Subject: [PATCH 84/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 24046f4..62f14e3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -61,7 +61,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && isNumber( value ) ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 961b7c4..55b70e7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-number": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From f2f4a8b587bd0aebf2a58472a095d5d5e34d3732 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 23 Mar 2025 11:19:39 +0000 Subject: [PATCH 85/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bd8ff22..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function n(n,o,a,j){var l;if(null===(l=d(o,1)))throw new TypeError(i("1d337",o));return/^complex/.test(o)&&"number"==typeof n&&(n=[n,0]),(s(l)?r(o):e(o))(l,0,n),new m(o,l,a,t(a.length),0,j)}export{n as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 12f2188..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && typeof value === 'number' ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;qqBAwDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAA4B,iBAAVD,IACvCA,EAAQ,CAAEA,EAAO,KAEbS,EAAiBL,GACfM,EAAgBT,GAEhBU,EAAQV,IAEVG,EAAK,EAAGJ,GACN,IAAIY,EAASX,EAAOG,EAAKF,EAAOW,EAAOX,EAAMY,QAAU,EAAGX,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9a924ce..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ffd16429074c8c3c5bb3d10afa265794c560bbe9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 23 Mar 2025 11:19:56 +0000 Subject: [PATCH 86/95] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 239 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 81 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 339 -- 43 files changed, 4867 insertions(+), 4651 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21e46b9..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index ca493af..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=o(function(z,t){"use strict";var c=require("@stdlib/assert-is-number").isPrimitive,v=require("@stdlib/array-base-assert-is-accessor-array"),q=require("@stdlib/array-base-accessor-setter"),f=require("@stdlib/array-base-setter"),m=require("@stdlib/array-base-zeros"),b=require("@stdlib/ndarray-base-buffer"),l=require("@stdlib/ndarray-base-ctor"),g=require("@stdlib/string-format");function w(e,r,s,n){var i,a;if(i=b(r,1),i===null)throw new TypeError(g("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&c(e)&&(e=[e,0]),v(i)?a=q(r):a=f(r),a(i,0,e),new l(r,i,s,m(s.length),0,n)}t.exports=w});var x=u();module.exports=x; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index fc691f7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EAGJ,GADAD,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAKV,EAAUS,CAAM,IAChDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACZ,IAAIH,EAASI,EAAOG,EAAKF,EAAOP,EAAOO,EAAM,MAAO,EAAG,EAAGC,CAAM,CACxE,CAKAb,EAAO,QAAUS,ICrCjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cc5fb9d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,a,j,l){var p;if(null===(p=i(a,1)))throw new TypeError(n("1d337",a));return/^complex/.test(a)&&s(o)&&(o=[o,0]),(r(p)?e(a):t(a))(p,0,o),new m(a,p,j,d(j.length),0,l)}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1771d45 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isNumber","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;+wBAyDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAAWQ,EAAUT,KAC1CA,EAAQ,CAAEA,EAAO,KAEbU,EAAiBN,GACfO,EAAgBV,GAEhBW,EAAQX,IAEVG,EAAK,EAAGJ,GACN,IAAIa,EAASZ,EAAOG,EAAKF,EAAOY,EAAOZ,EAAMa,QAAU,EAAGZ,EAClE"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 62f14e3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && isNumber( value ) ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - return new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 55b70e7..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1f61230 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5eb6c8a..0000000 --- a/test/test.js +++ /dev/null @@ -1,339 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); From 2397a1391e50a21cd73d6ac03f5f0677af3c42ed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 5 Apr 2025 09:29:16 +0000 Subject: [PATCH 87/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8b6ac2d..58a08ea 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,7 +62,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( /^complex/.test( dtype ) && isNumber( value ) ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 961b7c4..55b70e7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-number": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 91e099ff9c7e828309f550aa6a6e6442106dd13f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 5 Apr 2025 09:29:38 +0000 Subject: [PATCH 88/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cc5fb9d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,a,j,l){var p;if(null===(p=i(a,1)))throw new TypeError(n("1d337",a));return/^complex/.test(a)&&s(o)&&(o=[o,0]),(r(p)?e(a):t(a))(p,0,o),new m(a,p,j,d(j.length),0,l)}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1771d45..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\treturn new ndarray( dtype, buf, shape, zeros( shape.length ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","buffer","TypeError","format","test","isNumber","isAccessorArray","accessorSetter","setter","ndarray","zeros","length"],"mappings":";;+wBAyDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAIJ,GAAa,QADbA,EAAMC,EAAQJ,EAAO,IAEpB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAWvC,MATK,WAAWO,KAAMP,IAAWQ,EAAUT,KAC1CA,EAAQ,CAAEA,EAAO,KAEbU,EAAiBN,GACfO,EAAgBV,GAEhBW,EAAQX,IAEVG,EAAK,EAAGJ,GACN,IAAIa,EAASZ,EAAOG,EAAKF,EAAOY,EAAOZ,EAAMa,QAAU,EAAGZ,EAClE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1f61230..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 97893f9cda96015cb23a72083ee78f962b9c45a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 5 Apr 2025 09:30:03 +0000 Subject: [PATCH 89/95] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 250 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 83 - package.json | 78 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 43 files changed, 4867 insertions(+), 4682 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21e46b9..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 74a243c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var n=c(function(A,u){"use strict";var v=require("@stdlib/assert-is-number").isPrimitive,q=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-accessor-setter"),m=require("@stdlib/array-base-setter"),b=require("@stdlib/array-base-zeros"),l=require("@stdlib/ndarray-base-buffer"),g=require("@stdlib/ndarray-base-ctor"),w=require("@stdlib/string-format");function x(e,r,s,o){var a,i,t;if(a=l(r,1),a===null)throw new TypeError(w("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return/^complex/.test(r)&&v(e)&&(e=[e,0]),q(a)?i=f(r):i=m(r),i(a,0,e),t=s.length||1,new g(r,a,s,b(t),0,o)}u.exports=x});var S=n();module.exports=S; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 025b7b4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,MAAK,WAAW,KAAMA,CAAM,GAAKV,EAAUS,CAAM,IAChDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBR,EAAiBY,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACnBM,EAAIJ,EAAM,QAAU,EACb,IAAIL,EAASI,EAAOG,EAAKF,EAAOP,EAAOW,CAAE,EAAG,EAAGH,CAAM,CAC7D,CAKAb,EAAO,QAAUS,ICvCjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isAccessorArray", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "N", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b1ccbd1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,a,j,l){var p,h;if(null===(p=i(a,1)))throw new TypeError(n("1d337",a));return/^complex/.test(a)&&s(o)&&(o=[o,0]),(r(p)?e(a):t(a))(p,0,o),h=j.length||1,new m(a,p,j,d(h),0,l)}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f10c698 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","N","buffer","TypeError","format","test","isNumber","isAccessorArray","accessorSetter","setter","length","ndarray","zeros"],"mappings":";;+wBAyDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAEAC,EAGJ,GAAa,QADbD,EAAME,EAAQL,EAAO,IAEpB,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAYvC,MAVK,WAAWQ,KAAMR,IAAWS,EAAUV,KAC1CA,EAAQ,CAAEA,EAAO,KAEbW,EAAiBP,GACfQ,EAAgBX,GAEhBY,EAAQZ,IAEVG,EAAK,EAAGJ,GACbK,EAAIH,EAAMY,QAAU,EACb,IAAIC,EAASd,EAAOG,EAAKF,EAAOc,EAAOX,GAAK,EAAGF,EACvD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 58a08ea..0000000 --- a/lib/main.js +++ /dev/null @@ -1,83 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - var N; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( /^complex/.test( dtype ) && isNumber( value ) ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - N = shape.length || 1; - return new ndarray( dtype, buf, shape, zeros( N ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 55b70e7..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c1f8e13 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0788a9b..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic, ndims=0)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); From e1463b921154ab12b140a8d143da6d0f0f09441e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 27 Apr 2025 23:37:30 +0000 Subject: [PATCH 90/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4030edd..0715c04 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -63,7 +63,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( isComplexDataType( dtype ) && isNumber( value ) ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 6720507..2536cae 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-number": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 3ebb2988a5a9975f289eefe585b029dd66cf29e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 27 Apr 2025 23:37:55 +0000 Subject: [PATCH 91/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b1ccbd1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,a,j,l){var p,h;if(null===(p=i(a,1)))throw new TypeError(n("1d337",a));return/^complex/.test(a)&&s(o)&&(o=[o,0]),(r(p)?e(a):t(a))(p,0,o),h=j.length||1,new m(a,p,j,d(h),0,l)}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f10c698..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( /^complex/.test( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","N","buffer","TypeError","format","test","isNumber","isAccessorArray","accessorSetter","setter","length","ndarray","zeros"],"mappings":";;+wBAyDA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAEAC,EAGJ,GAAa,QADbD,EAAME,EAAQL,EAAO,IAEpB,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAYvC,MAVK,WAAWQ,KAAMR,IAAWS,EAAUV,KAC1CA,EAAQ,CAAEA,EAAO,KAEbW,EAAiBP,GACfQ,EAAgBX,GAEhBY,EAAQZ,IAEVG,EAAK,EAAGJ,GACbK,EAAIH,EAAMY,QAAU,EACb,IAAIC,EAASd,EAAOG,EAAKF,EAAOc,EAAOX,GAAK,EAAGF,EACvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c1f8e13..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1b3fcf3d2deeddf5fef47835852cdafc113d2991 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 27 Apr 2025 23:38:45 +0000 Subject: [PATCH 92/95] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 84 - package.json | 79 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 43 files changed, 4867 insertions(+), 4685 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21e46b9..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 15a342a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var n=v(function(N,u){"use strict";var c=require("@stdlib/assert-is-number").isPrimitive,q=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-assert-is-complex-floating-point-data-type"),m=require("@stdlib/array-base-accessor-setter"),b=require("@stdlib/array-base-setter"),l=require("@stdlib/array-base-zeros"),g=require("@stdlib/ndarray-base-buffer"),w=require("@stdlib/ndarray-base-ctor"),x=require("@stdlib/string-format");function S(e,r,s,o){var a,i,t;if(a=g(r,1),a===null)throw new TypeError(x("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return f(r)&&c(e)&&(e=[e,0]),q(a)?i=m(r):i=b(r),i(a,0,e),t=s.length||1,new w(r,a,s,l(t),0,o)}u.exports=S});var z=n();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3ceabaa..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( isComplexDataType( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,OAAKT,EAAmBS,CAAM,GAAKX,EAAUU,CAAM,IAClDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBT,EAAiBa,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACnBM,EAAIJ,EAAM,QAAU,EACb,IAAIL,EAASI,EAAOG,EAAKF,EAAOP,EAAOW,CAAE,EAAG,EAAGH,CAAM,CAC7D,CAKAd,EAAO,QAAUU,ICxCjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isAccessorArray", "isComplexDataType", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "N", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8cb1fca --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,j,l,p){var h,v;if(null===(h=m(j,1)))throw new TypeError(a("1d337",j));return e(j)&&s(o)&&(o=[o,0]),(r(h)?t(j):i(j))(h,0,o),v=l.length||1,new n(j,h,l,d(v),0,p)}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bd6ad2e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport isComplexDataType from '@stdlib/array-base-assert-is-complex-floating-point-data-type';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( isComplexDataType( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","N","buffer","TypeError","format","isComplexDataType","isNumber","isAccessorArray","accessorSetter","setter","length","ndarray","zeros"],"mappings":";;+4BA0DA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAEAC,EAGJ,GAAa,QADbD,EAAME,EAAQL,EAAO,IAEpB,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAYvC,OAVKQ,EAAmBR,IAAWS,EAAUV,KAC5CA,EAAQ,CAAEA,EAAO,KAEbW,EAAiBP,GACfQ,EAAgBX,GAEhBY,EAAQZ,IAEVG,EAAK,EAAGJ,GACbK,EAAIH,EAAMY,QAAU,EACb,IAAIC,EAASd,EAAOG,EAAKF,EAAOc,EAAOX,GAAK,EAAGF,EACvD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0715c04..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - var N; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( isComplexDataType( dtype ) && isNumber( value ) ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - N = shape.length || 1; - return new ndarray( dtype, buf, shape, zeros( N ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 2536cae..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe8db5b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0788a9b..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic, ndims=0)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); From b951546af1d8dbab1f491738015c1bab5518c573 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:34:32 +0000 Subject: [PATCH 93/95] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4030edd..0715c04 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var setter = require( '@stdlib/array-base-setter' ); var zeros = require( '@stdlib/array-base-zeros' ); var buffer = require( '@stdlib/ndarray-base-buffer' ); var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -63,7 +63,7 @@ function broadcastScalar( value, dtype, shape, order ) { buf = buffer( dtype, 1 ); if ( buf === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '1d337', dtype ) ); } if ( isComplexDataType( dtype ) && isNumber( value ) ) { value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components diff --git a/package.json b/package.json index 6720507..2536cae 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-number": "^0.2.2", "@stdlib/ndarray-base-buffer": "^0.3.0", "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d368410edd029b0bdf6032690c194d682e4a3f5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:35:25 +0000 Subject: [PATCH 94/95] Remove files --- index.d.ts | 349 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5196 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a773366..0000000 --- a/index.d.ts +++ /dev/null @@ -1,349 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexLike } from '@stdlib/types/complex'; -import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float64', shape: Shape, order: Order ): float64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float32' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: number, dtype: 'float32', shape: Shape, order: Order ): float32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex128 = require( '@stdlib/complex-float64-ctor' ); -* var real = require( '@stdlib/complex-float64-real' ); -* var imag = require( '@stdlib/complex-float64-imag' ); -* -* var v = new Complex128( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex128' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = real( v ); -* // returns 1.0 -* -* var im = imag( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex128', shape: Shape, order: Order ): complex128ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* ## Notes -* -* - If provided a number, the function returns an ndarray containing a complex number whose real component equals the provided scalar value and whose imaginary component is zero. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* -* var v = new Complex64( 1.0, 2.0 ); -* -* var x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'complex64' -* -* var v = x.get( 0, 1 ); -* // returns -* -* var re = realf( v ); -* // returns 1.0 -* -* var im = imagf( v ); -* // returns 2.0 -*/ -declare function broadcastScalar( value: number | ComplexLike, dtype: 'complex64', shape: Shape, order: Order ): complex64ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int32', shape: Shape, order: Order ): int32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int16', shape: Shape, order: Order ): int16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'int8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'int8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'int8', shape: Shape, order: Order ): int8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint32', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint32' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint32', shape: Shape, order: Order ): uint32ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint16', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint16' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint16', shape: Shape, order: Order ): uint16ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8', shape: Shape, order: Order ): uint8ndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1, 'uint8c', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'uint8c' -* -* var v = x.get( 0, 1 ); -* // returns 1 -*/ -declare function broadcastScalar( value: number, dtype: 'uint8c', shape: Shape, order: Order ): uint8cndarray; - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param value - scalar value -* @param dtype - array data type -* @param shape - array shape -* @param order - array order -* @returns ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'generic' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -declare function broadcastScalar( value: any, dtype: DataType, shape: Shape, order: Order ): ndarray; - - -// EXPORTS // - -export = broadcastScalar; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8cb1fca..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,j,l,p){var h,v;if(null===(h=m(j,1)))throw new TypeError(a("1d337",j));return e(j)&&s(o)&&(o=[o,0]),(r(h)?t(j):i(j))(h,0,o),v=l.length||1,new n(j,h,l,d(v),0,p)}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index bd6ad2e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport isComplexDataType from '@stdlib/array-base-assert-is-complex-floating-point-data-type';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( isComplexDataType( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","N","buffer","TypeError","format","isComplexDataType","isNumber","isAccessorArray","accessorSetter","setter","length","ndarray","zeros"],"mappings":";;+4BA0DA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAEAC,EAGJ,GAAa,QADbD,EAAME,EAAQL,EAAO,IAEpB,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAYvC,OAVKQ,EAAmBR,IAAWS,EAAUV,KAC5CA,EAAQ,CAAEA,EAAO,KAEbW,EAAiBP,GACfQ,EAAgBX,GAEhBY,EAAQZ,IAEVG,EAAK,EAAGJ,GACbK,EAAIH,EAAMY,QAAU,EACb,IAAIC,EAASd,EAAOG,EAAKF,EAAOc,EAAOX,GAAK,EAAGF,EACvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fe8db5b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 216408f359f4b98d4076433b41df82e67874a327 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:35:49 +0000 Subject: [PATCH 95/95] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 83 - examples/index.js | 33 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 49 - lib/main.js | 84 - package.json | 79 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 357 -- 44 files changed, 4867 insertions(+), 4686 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ea8300a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-05T00:33:43.386Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 21e46b9..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index d658f0e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b05baed..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '6 6 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -162,7 +153,7 @@ for ( i = 0; i < dt.length; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -225,11 +216,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-scalar/main/LICENSE -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8acd523..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var pkg = require( './../package.json' ).name; -var broadcastScalar = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype=float64', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'float32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex128( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex128', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var x; - var v; - var i; - - v = new Complex64( 1.0, 2.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( v, 'complex64', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint32', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint16', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'int8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'uint8c', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = broadcastScalar( i, 'generic', [ 2, 2 ], 'row-major' ); - if ( x.length !== 4 ) { - b.fail( 'should have length 4' ); - } - } - b.toc(); - if ( !isndarrayLike( x ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc1ada5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-scalar -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-scalar/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3badc58..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastScalar from '../docs/types/index'; -export = broadcastScalar; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 15a342a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var v=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var n=v(function(N,u){"use strict";var c=require("@stdlib/assert-is-number").isPrimitive,q=require("@stdlib/array-base-assert-is-accessor-array"),f=require("@stdlib/array-base-assert-is-complex-floating-point-data-type"),m=require("@stdlib/array-base-accessor-setter"),b=require("@stdlib/array-base-setter"),l=require("@stdlib/array-base-zeros"),g=require("@stdlib/ndarray-base-buffer"),w=require("@stdlib/ndarray-base-ctor"),x=require("@stdlib/string-format");function S(e,r,s,o){var a,i,t;if(a=g(r,1),a===null)throw new TypeError(x("invalid argument. Second argument must be a recognized data type. Value: `%s`.",r));return f(r)&&c(e)&&(e=[e,0]),q(a)?i=m(r):i=b(r),i(a,0,e),t=s.length||1,new w(r,a,s,l(t),0,o)}u.exports=S});var z=n();module.exports=z; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 3ceabaa..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( isComplexDataType( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastScalar;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast a scalar value to an ndarray having a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-scalar\n*\n* @example\n* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\n*\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,6BAA8B,EAChDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAiBC,EAAOC,EAAOC,EAAOC,EAAQ,CACtD,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAMR,EAAQK,EAAO,CAAE,EAClBG,IAAQ,KACZ,MAAM,IAAI,UAAWN,EAAQ,iFAAkFG,CAAM,CAAE,EAExH,OAAKT,EAAmBS,CAAM,GAAKX,EAAUU,CAAM,IAClDA,EAAQ,CAAEA,EAAO,CAAI,GAEjBT,EAAiBa,CAAI,EACzBC,EAAMZ,EAAgBQ,CAAM,EAE5BI,EAAMX,EAAQO,CAAM,EAErBI,EAAKD,EAAK,EAAGJ,CAAM,EACnBM,EAAIJ,EAAM,QAAU,EACb,IAAIL,EAASI,EAAOG,EAAKF,EAAOP,EAAOW,CAAE,EAAG,EAAGH,CAAM,CAC7D,CAKAd,EAAO,QAAUU,ICxCjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNumber", "isAccessorArray", "isComplexDataType", "accessorSetter", "setter", "zeros", "buffer", "ndarray", "format", "broadcastScalar", "value", "dtype", "shape", "order", "buf", "set", "N", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5b7a799..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( value, dtype, shape, order ) - Broadcasts a scalar value to an ndarray having a specified shape. - - If `value` is a number and `dtype` is a complex number data type, the - function returns an ndarray containing a complex number whose real component - equals the provided scalar value and whose imaginary component is zero. - - The returned array is a view on an ndarray data buffer. The view is *not* - contiguous. As more than one element of a returned view may refer to the - same memory location, writing to the view may affect multiple elements. If - you need to write to the returned array, copy the array before performing - operations which may mutate elements. - - The returned array is a "base" ndarray, and, thus, the returned array does - not perform bounds checking or afford any of the guarantees of the non-base - ndarray constructor. The primary intent of this function is to broadcast a - scalar value as an ndarray within internal implementations and to do so with - minimal overhead. - - Parameters - ---------- - value: any - Scalar value. - - dtype: string - Data type. - - shape: ArrayLike - Array shape. - - order: string - Memory layout (either 'row-major' or 'column-major'). - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var x = {{alias}}( 1.0, 'float64', [ 2, 2 ], 'row-major' ) - - > var sh = x.shape - [ 2, 2 ] - > var dt = x.dtype - 'float64' - > var v = x.get( 0, 1 ) - 1.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ba14852..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import broadcastScalar = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); // $ExpectType float64ndarray - broadcastScalar( 1.0, 'float32', [ 2, 2 ], 'row-major' ); // $ExpectType float32ndarray - broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); // $ExpectType complex128ndarray - broadcastScalar( 1.0, 'complex64', [ 2, 2 ], 'row-major' ); // $ExpectType complex64ndarray - broadcastScalar( 1.0, 'int32', [ 2, 2 ], 'row-major' ); // $ExpectType int32ndarray - broadcastScalar( 1.0, 'int16', [ 2, 2 ], 'row-major' ); // $ExpectType int16ndarray - broadcastScalar( 1.0, 'int8', [ 2, 2 ], 'row-major' ); // $ExpectType int8ndarray - broadcastScalar( 1.0, 'uint32', [ 2, 2 ], 'row-major' ); // $ExpectType uint32ndarray - broadcastScalar( 1.0, 'uint16', [ 2, 2 ], 'row-major' ); // $ExpectType uint16ndarray - broadcastScalar( 1.0, 'uint8', [ 2, 2 ], 'row-major' ); // $ExpectType uint8ndarray - broadcastScalar( 1.0, 'uint8c', [ 2, 2 ], 'row-major' ); // $ExpectType uint8cndarray - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized/supported data type... -{ - broadcastScalar( 1.0, '10', [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 5, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, false, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, true, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, null, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, [], [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, {}, [ 2, 2 ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a valid shape... -{ - broadcastScalar( 1.0, 'float64', '10', 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', 5, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', false, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', true, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', null, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ '1' ], 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', {}, 'row-major' ); // $ExpectError - broadcastScalar( 1.0, 'float64', ( x: number ): number => x, 'row-major' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid order... -{ - broadcastScalar( 1.0, 'generic', [ 2, 2 ], '10' ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], 5 ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], false ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], true ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], null ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], [] ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], {} ); // $ExpectError - broadcastScalar( 1.0, 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastScalar(); // $ExpectError - broadcastScalar( 1.0 ); // $ExpectError - broadcastScalar( 1.0, 'float64' ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ] ); // $ExpectError - broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major', 1 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e3b5557..0000000 --- a/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var broadcastScalar = require( './../lib' ); - -// Get a list of data types: -var dt = dtypes(); - -// Generate two-dimensional arrays... -var x; -var i; -for ( i = 0; i < dt.length; i++ ) { - x = broadcastScalar( i, dt[ i ], [ 2, 2 ], 'row-major' ); - console.log( x.get( 0, 1 ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 04624f9..a773366 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ComplexLike } from '@stdlib/types/complex'; import { ndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray, DataType, Shape, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8cb1fca --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function o(o,j,l,p){var h,v;if(null===(h=m(j,1)))throw new TypeError(a("1d337",j));return e(j)&&s(o)&&(o=[o,0]),(r(h)?t(j):i(j))(h,0,o),v=l.length||1,new n(j,h,l,d(v),0,p)}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bd6ad2e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport isComplexDataType from '@stdlib/array-base-assert-is-complex-floating-point-data-type';\nimport accessorSetter from '@stdlib/array-base-accessor-setter';\nimport setter from '@stdlib/array-base-setter';\nimport zeros from '@stdlib/array-base-zeros';\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Broadcasts a scalar value to an ndarray having a specified shape.\n*\n* @param {*} value - scalar value\n* @param {string} dtype - output array data type\n* @param {NonNegativeIntegerArray} shape - output array shape\n* @param {string} order - memory layout (either row-major or column-major)\n* @throws {TypeError} second argument must be a recognized data type\n* @returns {ndarray} ndarray\n*\n* @example\n* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' );\n* // returns \n*\n* var sh = x.shape;\n* // returns [ 2, 2 ]\n*\n* var dt = x.dtype;\n* // returns 'float64'\n*\n* var v = x.get( 0, 1 );\n* // returns 1.0\n*/\nfunction broadcastScalar( value, dtype, shape, order ) {\n\tvar buf;\n\tvar set;\n\tvar N;\n\n\tbuf = buffer( dtype, 1 );\n\tif ( buf === null ) {\n\t\tthrow new TypeError( format( '1d337', dtype ) );\n\t}\n\tif ( isComplexDataType( dtype ) && isNumber( value ) ) {\n\t\tvalue = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components\n\t}\n\tif ( isAccessorArray( buf ) ) {\n\t\tset = accessorSetter( dtype );\n\t} else {\n\t\tset = setter( dtype );\n\t}\n\tset( buf, 0, value );\n\tN = shape.length || 1;\n\treturn new ndarray( dtype, buf, shape, zeros( N ), 0, order );\n}\n\n\n// EXPORTS //\n\nexport default broadcastScalar;\n"],"names":["broadcastScalar","value","dtype","shape","order","buf","N","buffer","TypeError","format","isComplexDataType","isNumber","isAccessorArray","accessorSetter","setter","length","ndarray","zeros"],"mappings":";;+4BA0DA,SAASA,EAAiBC,EAAOC,EAAOC,EAAOC,GAC9C,IAAIC,EAEAC,EAGJ,GAAa,QADbD,EAAME,EAAQL,EAAO,IAEpB,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAYvC,OAVKQ,EAAmBR,IAAWS,EAAUV,KAC5CA,EAAQ,CAAEA,EAAO,KAEbW,EAAiBP,GACfQ,EAAgBX,GAEhBY,EAAQZ,IAEVG,EAAK,EAAGJ,GACbK,EAAIH,EAAMY,QAAU,EACb,IAAIC,EAASd,EAAOG,EAAKF,EAAOc,EAAOX,GAAK,EAAGF,EACvD"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9143503..0000000 --- a/lib/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast a scalar value to an ndarray having a specified shape. -* -* @module @stdlib/ndarray-base-broadcast-scalar -* -* @example -* var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -* -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0715c04..0000000 --- a/lib/main.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts a scalar value to an ndarray having a specified shape. -* -* @param {*} value - scalar value -* @param {string} dtype - output array data type -* @param {NonNegativeIntegerArray} shape - output array shape -* @param {string} order - memory layout (either row-major or column-major) -* @throws {TypeError} second argument must be a recognized data type -* @returns {ndarray} ndarray -* -* @example -* var x = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 2, 2 ] -* -* var dt = x.dtype; -* // returns 'float64' -* -* var v = x.get( 0, 1 ); -* // returns 1.0 -*/ -function broadcastScalar( value, dtype, shape, order ) { - var buf; - var set; - var N; - - buf = buffer( dtype, 1 ); - if ( buf === null ) { - throw new TypeError( format( '1d337', dtype ) ); - } - if ( isComplexDataType( dtype ) && isNumber( value ) ) { - value = [ value, 0.0 ]; // note: we're assuming that the ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dtype ); - } else { - set = setter( dtype ); - } - set( buf, 0, value ); - N = shape.length || 1; - return new ndarray( dtype, buf, shape, zeros( N ), 0, order ); -} - - -// EXPORTS // - -module.exports = broadcastScalar; diff --git a/package.json b/package.json index 2536cae..f0f86ed 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast a scalar value to an ndarray having a specified shape.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fe8db5b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0788a9b..0000000 --- a/test/test.js +++ /dev/null @@ -1,357 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var base = require( '@stdlib/ndarray-base-ctor' ); -var broadcastScalar = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastScalar, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a second argument which is not a recognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beepboop', - 'foo', - 'bar', - 5, - 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() { - broadcastScalar( 1.0, value, [ 2, 2 ], 'row-major' ); - }; - } -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float64', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float64Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0 ] ); - arr = broadcastScalar( 1.0, 'float32', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'float32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Float32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int32', [ 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int16', [ 1, 2 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'int8', [ 3, 3, 3 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'int8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Int8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 27, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint32', [ 1, 2, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint32', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 2, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint32Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint16', [ 3, 2, 1 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint16', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 2, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint16Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 6, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8', [ 1, 1, 1, 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1, 1, 1, 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 1 ] ); - arr = broadcastScalar( 1, 'uint8c', [ 2, 0, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'uint8c', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 0, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Uint8ClampedArray ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float64Array( [ 1.0, 2.0 ] ); - - v = new Complex128( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex128', [ 1 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 1 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex128, real)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex128', [ 2, 2 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex128', 'returns expected value' ); - t.deepEqual( arr.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex128Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret128( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, complex)', function test( t ) { - var expected; - var arr; - var v; - - expected = new Float32Array( [ 1.0, 2.0 ] ); - - v = new Complex64( 1.0, 2.0 ); - arr = broadcastScalar( v, 'complex64', [ 3, 3 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 3, 3 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 9, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=complex64, real)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 1.0, 0.0 ] ); - arr = broadcastScalar( 1.0, 'complex64', [ 4, 4 ], 'row-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'complex64', 'returns expected value' ); - t.deepEqual( arr.shape, [ 4, 4 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Complex64Array ), true, 'returns expected value' ); - t.deepEqual( reinterpret64( arr.data, 0 ), expected, 'returns expected value' ); - t.strictEqual( arr.order, 'row-major', 'returns expected value' ); - t.strictEqual( arr.length, 16, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [ 0, 2, 0 ], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [ 0, 2, 0 ], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a broadcasted ndarray (dtype=generic, ndims=0)', function test( t ) { - var expected; - var arr; - - expected = [ 1 ]; - arr = broadcastScalar( 1, 'generic', [], 'column-major' ); - - t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); - t.strictEqual( arr.dtype, 'generic', 'returns expected value' ); - t.deepEqual( arr.shape, [], 'returns expected value' ); - t.strictEqual( instanceOf( arr.data, Array ), true, 'returns expected value' ); - t.deepEqual( arr.data, expected, 'returns expected value' ); - t.strictEqual( arr.order, 'column-major', 'returns expected value' ); - t.strictEqual( arr.length, 1, 'returns expected value' ); - - t.end(); -});