From 7d489709907bf24a452d230952e8d7bbe32ecbb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 Jan 2026 05:16:49 +0000 Subject: [PATCH 01/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae8b74e..c5d3ac2 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.1", "@stdlib/ndarray-zeros": "^0.3.0", "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From 518c254f02cb90af2e1ceb6cf7003de3b7995c6f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 Jan 2026 05:17:38 +0000 Subject: [PATCH 02/30] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 55 files changed, 4889 insertions(+), 8289 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -414,7 +411,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -477,17 +474,17 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..52675ad --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2a1aa99 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;kZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index c5d3ac2..1d040c7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/random-base-triangular": "^0.2.1", - "@stdlib/random-tools-ternary-factory": "github:stdlib-js/random-tools-ternary-factory#main", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.2.1", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-same-float64array": "^0.2.2", - "@stdlib/assert-is-uint32array": "^0.2.2", - "@stdlib/console-log-each": "^0.2.2", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-cbrt": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sqrt": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-numel": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-minstd": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..11d81c9 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 6971fee4616d1bb69ed963215bad2a1a1e76cdf6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:03:53 +0000 Subject: [PATCH 03/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d4b9e6..ca6b082 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.1", "@stdlib/ndarray-zeros": "^0.3.0", "@stdlib/random-base-minstd": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From 8717f4e3f915cbda801b2100d29113335eadde04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:09:06 +0000 Subject: [PATCH 04/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 52675ad..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2a1aa99..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;kZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 11d81c9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c06622b7cd3feed9655808217852b036de1eda22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:09:34 +0000 Subject: [PATCH 05/30] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 55 files changed, 4889 insertions(+), 8289 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -414,7 +411,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -477,17 +474,17 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1ba7fe0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2a1aa99 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;kZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index ca6b082..fa1ce3c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.0", - "@stdlib/random-base-triangular": "^0.2.1", - "@stdlib/random-tools-ternary-factory": "github:stdlib-js/random-tools-ternary-factory#main", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.0", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-same-float64array": "^0.2.2", - "@stdlib/assert-is-uint32array": "^0.2.2", - "@stdlib/console-log-each": "^0.2.3", - "@stdlib/constants-uint32-max": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-cbrt": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sqrt": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-numel": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-minstd": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5fd0e04 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 38d0cca6d99e06bd257e8d5f2acc8883af3badb2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:36:18 +0000 Subject: [PATCH 06/30] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b946865..879b4a6 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; ``` #### triangular( shape, a, b, c\[, options] ) @@ -353,7 +353,7 @@ var sz = random.byteLength; import logEach from 'https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; // Create a function for generating random arrays originating from the same state: var random = triangular.factory({ From 899120f50513859377715549c33f997041d0f0e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:36:19 +0000 Subject: [PATCH 07/30] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 879b4a6..7dfbc17 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ limitations under the License. ## Usage +```javascript +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/random-triangular/tags). For example, + ```javascript import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; ``` @@ -48,7 +53,7 @@ import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@ You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; ``` #### triangular( shape, a, b, c\[, options] ) @@ -353,7 +358,7 @@ var sz = random.byteLength; import logEach from 'https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.0-esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; // Create a function for generating random arrays originating from the same state: var random = triangular.factory({ From 48b43d4709146a474d1bbf7c2074774a33018134 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:31:13 +0000 Subject: [PATCH 08/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff3358f..d80bc4f 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.1", "@stdlib/ndarray-zeros": "^0.3.0", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From b85023a595fe8428081077833c85e77eda0d0e93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:27:55 +0000 Subject: [PATCH 09/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1ba7fe0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.1-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2a1aa99..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;kZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5fd0e04..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 69fe818862762daeeffffb5e6eca4ae1c8461946 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:28:21 +0000 Subject: [PATCH 10/30] 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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 58 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 55 files changed, 4889 insertions(+), 8292 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.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 e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -414,7 +411,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -477,17 +474,17 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..600efdc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..00272f7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index d80bc4f..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.0", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-same-float64array": "^0.2.2", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6baa5b0 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 7c86f7e5bdb3343ef63a546484aefbd003ab824f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:50:44 +0000 Subject: [PATCH 11/30] Update README.md for ESM bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b713ac..fb570f9 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; ``` #### triangular( shape, a, b, c\[, options] ) @@ -353,7 +353,7 @@ var sz = random.byteLength; import logEach from 'https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; // Create a function for generating random arrays originating from the same state: var random = triangular.factory({ From ed196605bb7f31329eca70cdb2c95d2a2629688d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:50:44 +0000 Subject: [PATCH 12/30] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb570f9..e421629 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ limitations under the License. ## Usage +```javascript +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/random-triangular/tags). For example, + ```javascript import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; ``` @@ -48,7 +53,7 @@ import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@ You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; ``` #### triangular( shape, a, b, c\[, options] ) @@ -353,7 +358,7 @@ var sz = random.byteLength; import logEach from 'https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@v0.1.1-esm/index.mjs'; +import triangular from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-triangular@esm/index.mjs'; // Create a function for generating random arrays originating from the same state: var random = triangular.factory({ From 4291e3f4897a908602ed4a9fa9099b150b6085f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:41:43 +0000 Subject: [PATCH 13/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2808e56..1d173ae 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From 18af5ae2c1803793574dea69769bf9df48c84add Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 04:07:57 +0000 Subject: [PATCH 14/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 600efdc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 00272f7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6baa5b0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f0a7ec94a7ba0005b3a2e34c09564225af49e430 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 04:08:33 +0000 Subject: [PATCH 15/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 58 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 56 files changed, 4889 insertions(+), 8304 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 209e83c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-10T03:31:39.907Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -414,7 +411,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -477,17 +474,17 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..00272f7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 1d173ae..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6ad6523 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 2d9c6e0f4da9fed969790c57b574dbb579149e4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 03:47:04 +0000 Subject: [PATCH 16/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2808e56..1d173ae 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From e0fe1c0d079eb375f220bfacc53e85807ad11e49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 04:00:01 +0000 Subject: [PATCH 17/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4685e19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 00272f7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ad6523..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1412bf544f8f3e2b441581a6956a8582d0e19096 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 04:00:30 +0000 Subject: [PATCH 18/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 58 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 56 files changed, 4889 insertions(+), 8322 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b99628d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-21T03:37:30.843Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -414,7 +411,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -477,17 +474,17 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..00272f7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 1d173ae..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6ad6523 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 814bafba4fb102f6878c9ec65077fb547261a957 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Jun 2026 03:21:20 +0000 Subject: [PATCH 19/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ae3ca8..5735fd8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From 587599c9cec70cc509015436e41185c9e56684b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Jun 2026 03:21:39 +0000 Subject: [PATCH 20/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4685e19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 00272f7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ad6523..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8c79b48fb25ad433088b3a58e64de29a516b034b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 8 Jun 2026 03:22:20 +0000 Subject: [PATCH 21/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 80 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 55 files changed, 4890 insertions(+), 8344 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -421,7 +418,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -484,21 +481,21 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7e5c99d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var a=t(function(F,i){ -var v=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),_=require('@stdlib/random-base-triangular/dist'),u=e("real_and_generic"),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_floating_point_and_generic"),l={output:"real_floating_point_and_generic"},g=v(_,[u,p,d],y,l);i.exports=g -});var s=t(function(O,n){ -var q=a(),f=q();n.exports=f -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),b=a();x(c,"factory",b);module.exports=c; -/** @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 9073175..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..00272f7 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b19c370..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 5735fd8..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6ad6523 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 42866149f374ee1ff9f9873e9178af5d6de74ea0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 25 Jun 2026 07:20:47 +0000 Subject: [PATCH 22/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ae3ca8..5735fd8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From ea62bdfebd49b5435a834c2da0cc93115ca4b928 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 25 Jun 2026 07:55:21 +0000 Subject: [PATCH 23/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4685e19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 00272f7..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ad6523..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f8eb5e3c206e3ce8d3462af443414282a8aa1958 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 25 Jun 2026 07:55:48 +0000 Subject: [PATCH 24/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 93 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 55 files changed, 4890 insertions(+), 8357 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -421,7 +418,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -484,21 +481,21 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 132b6cd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){try{return r||o((r={exports:{}}).exports,r),r.exports}catch(v){throw (r=0, v)}};};var a=t(function(O,i){ -var _=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),u=require('@stdlib/random-base-triangular/dist'),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_and_generic"),l=e("real_floating_point_and_generic"),g={output:"real_floating_point_and_generic"},q=_(u,[p,d,y],l,g);i.exports=q -});var s=t(function(R,n){ -var f=a(),x=f();n.exports=x -});var b=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),m=a();b(c,"factory",m);module.exports=c; -/** @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 947acfa..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bec81c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 74a0457..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 5735fd8..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b430c56 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From df7437ced6cc0681c5d82069038b315a58011130 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:23:51 +0000 Subject: [PATCH 25/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ae3ca8..5735fd8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From 952a20bbedb517745115d2f46357e7ce0894d01b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:35:27 +0000 Subject: [PATCH 26/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4685e19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index bec81c4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b430c56..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d03b1e16483fae831bab013d4dfe14272b26212a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:35:56 +0000 Subject: [PATCH 27/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 93 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 56 files changed, 4890 insertions(+), 8358 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7c8f6bd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-07-02T03:21:41.387Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -421,7 +418,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -484,21 +481,21 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 132b6cd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){try{return r||o((r={exports:{}}).exports,r),r.exports}catch(v){throw (r=0, v)}};};var a=t(function(O,i){ -var _=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),u=require('@stdlib/random-base-triangular/dist'),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_and_generic"),l=e("real_floating_point_and_generic"),g={output:"real_floating_point_and_generic"},q=_(u,[p,d,y],l,g);i.exports=q -});var s=t(function(R,n){ -var f=a(),x=f();n.exports=x -});var b=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),m=a();b(c,"factory",m);module.exports=c; -/** @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 947acfa..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bec81c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 74a0457..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 5735fd8..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b430c56 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -}); From 63e3240fe54c65870348b9452d165e5cbfc29b06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:18:10 +0000 Subject: [PATCH 28/30] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ae3ca8..5735fd8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@stdlib/ndarray-to-array": "^0.2.2", "@stdlib/ndarray-zeros": "^0.3.1", "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", From a9cf3c6e47c0ed749e8525926b7a47e8d82d7d94 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:39:52 +0000 Subject: [PATCH 29/30] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 e891f45..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; -import * as random from '@stdlib/types/random'; - -/** -* Output array. -*/ -type RandomArray = floatndarray | genericndarray; - -/** -* Interface defining PRNG options. -*/ -interface PRNGOptions { - /** - * Pseudorandom number generator which generates uniformly distributed pseudorandom numbers. - */ - prng?: random.PRNG; - - /** - * Pseudorandom number generator seed. - */ - seed?: random.PRNGSeedMT19937; - - /** - * Pseudorandom number generator state. - */ - state?: random.PRNGStateMT19937; - - /** - * Specifies whether to copy a provided pseudorandom number generator state. Default: true. - */ - copy?: boolean; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - */ - dtype?: DataType; - - /** - * Specifies whether an array is row-major (C-style) or column-major (Fortran-style). Default: 'row-major'. - */ - order?: Order; - - /** - * Specifies how to handle a linear index which exceeds array dimensions. Default: 'throw'. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis. Default: ['throw']. - */ - submode?: Array; - - /** - * Boolean indicating whether an array should be read-only. Default: false. - */ - readonly?: boolean; -} - -/** -* Interface for PRNG properties and methods. -*/ -interface PRNG { - /** - * Underlying pseudorandom number generator. - */ - readonly PRNG: random.PRNG; - - /** - * PRNG seed. - */ - readonly seed: random.PRNGSeedMT19937 | null; - - /** - * PRNG seed length. - */ - readonly seedLength: number | null; - - /** - * PRNG state. - */ - state: random.PRNGStateMT19937 | null; - - /** - * PRNG state length. - */ - readonly stateLength: number | null; - - /** - * PRNG state size (in bytes). - */ - readonly byteLength: number | null; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface RandomFunction extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; -} - -/** -* Interface for generating pseudorandom numbers drawn from a triangular distribution. -*/ -interface Random extends PRNG { - /** - * Returns an ndarray containing pseudorandom numbers drawn from a triangular distribution. - * - * @param shape - output shape - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param options - function options - * @throws distribution parameters and the output shape must be broadcast compatible - * @returns output ndarray - * - * @example - * var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - , U extends typedndarray, V extends typedndarray>( shape: Shape, a: number | T, b: number | U, c: number | V, options?: Options ): RandomArray; - - /** - * Fills an ndarray with pseudorandom numbers drawn from a triangular distribution. - * - * @param a - minimum support - * @param b - maximum support - * @param c - mode - * @param out - output ndarray - * @throws distribution parameters and the output ndarray must be broadcast compatible - * @returns output ndarray - * - * @example - * var zeros = require( '@stdlib/ndarray-zeros' ); - * - * var out = zeros( [ 3, 3 ] ); - * // returns - * - * var v = triangular.assign( 2.0, 5.0, 3.0, out ); - * // returns - * - * var bool = ( out === v ); - * // returns true - */ - assign, U extends typedndarray, V extends typedndarray, W extends typedndarray>( a: number | T, b: number | U, c: number | V, out: W ): W; - - /** - * Returns a function for creating ndarrays containing pseudorandom numbers drawn from a triangular distribution. - * - * @param options - function options - * @throws must provide a valid state - * @returns function for creating ndarrays - * - * @example - * var random = triangular.factory(); - * - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - * - * @example - * var random = triangular.factory({ - * 'seed': 297 - * }); - * var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); - * // returns - */ - factory( options?: PRNGOptions ): RandomFunction; -} - -/** -* Generates pseudorandom numbers drawn from a triangular distribution. -* -* @param shape - output shape -* @param a - minimum support -* @param b - maximum support -* @param c - mode -* @param options - function options -* @throws distribution parameters and the output shape must be broadcast compatible -* @returns output ndarray -* -* @example -* var out = triangular( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var zeros = require( '@stdlib/ndarray-zeros' ); -* -* var out = zeros( [ 3, 3 ] ); -* // returns -* -* var v = triangular.assign( 2.0, 5.0, 3.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -* -* @example -* var random = triangular.factory(); -* -* var out = random( [ 3, 3 ], 2.0, 5.0, 3.0 ); -* // returns -*/ -declare var triangular: Random; - - -// EXPORTS // - -export = triangular; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4685e19..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index bec81c4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b430c56..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8f2ba818aaef26b996d7bdb237a3593ce7cb206b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:40:24 +0000 Subject: [PATCH 30/30] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .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 | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 93 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.1d.js | 127 - benchmark/benchmark.2d.js | 139 - benchmark/benchmark.3d.assign.js | 140 - benchmark/benchmark.3d.broadcast.js | 161 - benchmark/benchmark.3d.js | 139 - benchmark/benchmark.3d.same_shape.js | 161 - benchmark/benchmark.4d.js | 138 - benchmark/benchmark.5d.js | 138 - benchmark/benchmark.factory.js | 68 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 215 - docs/types/test.ts | 442 -- examples/index.js | 53 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 77 - lib/index.js | 77 - lib/main.js | 65 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.assign.js | 314 -- test/test.factory.js | 1209 ----- test/test.js | 74 - test/test.main.js | 883 ---- 56 files changed, 4890 insertions(+), 8359 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.1d.js delete mode 100644 benchmark/benchmark.2d.js delete mode 100644 benchmark/benchmark.3d.assign.js delete mode 100644 benchmark/benchmark.3d.broadcast.js delete mode 100644 benchmark/benchmark.3d.js delete mode 100644 benchmark/benchmark.3d.same_shape.js delete mode 100644 benchmark/benchmark.4d.js delete mode 100644 benchmark/benchmark.5d.js delete mode 100644 benchmark/benchmark.factory.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 (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/factory.js 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.assign.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js delete mode 100644 test/test.main.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fccec48..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-20T03:11:12.279Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e8768be..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/random/triangular) 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 b414457..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/random/triangular) 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 776420c..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: '25 13 * * 1' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -421,7 +418,7 @@ logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); ## 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]. @@ -484,21 +481,21 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-triangular/main/LICENSE -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray-output-dtype-policies/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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular +[@stdlib/random/array/triangular]: https://github.com/stdlib-js/random-array-triangular/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.1d.js b/benchmark/benchmark.1d.js deleted file mode 100644 index 4c313aa..0000000 --- a/benchmark/benchmark.1d.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.2d.js b/benchmark/benchmark.2d.js deleted file mode 100644 index 0da3a84..0000000 --- a/benchmark/benchmark.2d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var sqrt = require( '@stdlib/math-base-special-sqrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( sqrt( len ) ); - sh = [ len, len ]; - len *= len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.assign.js b/benchmark/benchmark.3d.assign.js deleted file mode 100644 index 02e25ac..0000000 --- a/benchmark/benchmark.3d.assign.js +++ /dev/null @@ -1,140 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ).assign; - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var x = zeros( shape, { - 'dtype': dtype, - 'order': order - }); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = random( PARAM1, PARAM2, PARAM3, x ); - if ( isnan( out.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== x || isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:assign:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.broadcast.js b/benchmark/benchmark.3d.broadcast.js deleted file mode 100644 index 3543878..0000000 --- a/benchmark/benchmark.3d.broadcast.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - var d; - - d = shape[ shape.length-1 ]; - param1 = array( filledarray( PARAM1, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param2 = array( filledarray( PARAM2, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - param3 = array( filledarray( PARAM3, d, dtype ), { - 'shape': [ d ], - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::broadcast:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.js b/benchmark/benchmark.3d.js deleted file mode 100644 index ad602f4..0000000 --- a/benchmark/benchmark.3d.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.3d.same_shape.js b/benchmark/benchmark.3d.same_shape.js deleted file mode 100644 index c60f67d..0000000 --- a/benchmark/benchmark.3d.same_shape.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var cbrt = require( '@stdlib/math-base-special-cbrt' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var array = require( '@stdlib/ndarray-array' ); -var filledarray = require( '@stdlib/array-filled' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var param1; - var param2; - var param3; - var opts; - - param1 = array( filledarray( PARAM1, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param2 = array( filledarray( PARAM2, len, dtype ), { - 'shape': shape, - 'order': order - }); - - param3 = array( filledarray( PARAM3, len, dtype ), { - 'shape': shape, - 'order': order - }); - - opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, param1, param2, param3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( cbrt( len ) ); - sh = [ len, len, len ]; - len *= len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s::same_shape:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.4d.js b/benchmark/benchmark.4d.js deleted file mode 100644 index 43ab68c..0000000 --- a/benchmark/benchmark.4d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/4.0 ) ); - sh = [ len, len, len, len ]; - len *= len * len * len; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.5d.js b/benchmark/benchmark.5d.js deleted file mode 100644 index 41083a1..0000000 --- a/benchmark/benchmark.5d.js +++ /dev/null @@ -1,138 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var orders = require( '@stdlib/ndarray-orders' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var random = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'generic' -]; -var ORDERS = orders(); -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - ndarray length -* @param {NonNegativeIntegerArray} shape - ndarray shape -* @param {string} dtype - output ndarray data type -* @param {string} order - output ndarray memory layout -* @returns {Function} benchmark function -*/ -function createBenchmark( len, shape, dtype, order ) { - var opts = { - 'dtype': dtype, - 'order': order - }; - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x = random( shape, PARAM1, PARAM2, PARAM3, opts ); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( x.data[ i%len ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var ord; - var sh; - var t1; - var f; - var i; - var j; - var k; - - min = 1; // 10^min - max = 5; // 10^max - - for ( k = 0; k < ORDERS.length; k++ ) { - ord = ORDERS[ k ]; - for ( j = 0; j < DTYPES.length; j++ ) { - t1 = DTYPES[ j ]; - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - sh = [ len/2, 2, 1, 1, 1 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - sh = [ 1, 1, 1, 2, len/2 ]; - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - - len = floor( pow( len, 1.0/5.0 ) ); - sh = [ len, len, len, len, len ]; - len *= pow( len, 4 ); - f = createBenchmark( len, sh, t1, ord ); - bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,xtype=%s', pkg, sh.length, len, sh.join( ',' ), ord, t1 ), f ); - } - } - } -} - -main(); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index b4d4498..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib' ).factory; - - -// MAIN // - -bench( format( '%s::no_options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory(); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::options:factory', pkg ), function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = factory( {} ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c128436..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/random/triangular" -%% click B href "https://github.com/stdlib-js/random-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-triangular/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/triangular -[production-url]: https://github.com/stdlib-js/random-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-triangular/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 8dbf870..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import triangular from '../docs/types/index'; -export = triangular; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 132b6cd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var t=function(o,r){return function(){try{return r||o((r={exports:{}}).exports,r),r.exports}catch(v){throw (r=0, v)}};};var a=t(function(O,i){ -var _=require('@stdlib/random-tools-ternary-factory/dist'),e=require('@stdlib/ndarray-dtypes/dist'),u=require('@stdlib/random-base-triangular/dist'),p=e("real_and_generic"),d=e("real_and_generic"),y=e("real_and_generic"),l=e("real_floating_point_and_generic"),g={output:"real_floating_point_and_generic"},q=_(u,[p,d,y],l,g);i.exports=q -});var s=t(function(R,n){ -var f=a(),x=f();n.exports=x -});var b=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=s(),m=a();b(c,"factory",m);module.exports=c; -/** @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 947acfa..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory = require( '@stdlib/random-tools-ternary-factory' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' );\nvar base = require( '@stdlib/random-base-triangular' );\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nmodule.exports = triangular;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var triangular = require( '@stdlib/random-triangular' );\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,sCAAuC,EAChEC,EAAS,QAAS,wBAAyB,EAC3CC,EAAO,QAAS,gCAAiC,EAKjDC,EAAWF,EAAQ,kBAAmB,EACtCG,EAAWH,EAAQ,kBAAmB,EACtCI,EAAWJ,EAAQ,kBAAmB,EACtCK,EAAUL,EAAQ,iCAAkC,EACpDM,EAAW,CACd,OAAU,iCACX,EAoCIC,EAAUR,EAAeE,EAAM,CAAEC,EAAUC,EAAUC,CAAS,EAAGC,EAASC,CAAS,EAKvFR,EAAO,QAAUS,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAqCVC,EAAaD,EAAQ,EAKzBD,EAAO,QAAUE,ICFjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_factory", "__commonJSMin", "exports", "module", "createFactory", "dtypes", "base", "idtypes1", "idtypes2", "idtypes3", "odtypes", "policies", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "triangular", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d2e1216..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,215 +0,0 @@ - -{{alias}}( shape, a, b, c[, options] ) - Returns an ndarray containing pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - shape: Array - Array shape. - - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - specified array shape. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the specified - array shape. - - options: Object (optional) - Options. - - options.dtype: string|DataType (optional) - Array data type. Must be a real-valued floating-point or "generic" data - type. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). Default: 'row-major'. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions to - either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'wrap', an ndarray instance wraps around subscripts exceeding - array dimensions using modulo arithmetic. If equal to 'clamp', an - ndarray instance sets a subscript exceeding array dimensions to either - `0` (minimum index) or the maximum index. If the number of modes is - less than the number of dimensions, an ndarray instance recycles modes - using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.assign( a, b, c, out ) - Fills an ndarray with pseudorandom numbers drawn from a triangular - distribution. - - Parameters - ---------- - a: number|ndarray - Minimum support. If an ndarray, must be broadcast compatible with the - provided output array. - - b: number|ndarray - Maximum support. If an ndarray, must be broadcast compatible with the - provided output array. - - c: number|ndarray - Mode. If an ndarray, must be broadcast compatible with the provided - output array. - - out: ndarray - Output array. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ); - > var v = {{alias}}.assign( 2.0, 5.0, 3.0, out ) - - > var bool = ( v === out ) - true - - -{{alias}}.factory( [options] ) - Returns a function for generating pseudorandom numbers drawn from a - triangular distribution. - - The returned function has the same signature and accepts the same options as - `{{alias}}` above. - - Parameters - ---------- - options: Object (optional) - Options. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned pseudorandom number generator, one must seed the provided - `prng` (assuming the provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned generator has exclusive control over - its internal state. Default: true. - - Returns - ------- - fcn: Function - Function for creating arrays. - - Examples - -------- - > var fcn = {{alias}}.factory(); - > var out = fcn( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.PRNG - Underlying pseudorandom number generator. - - Examples - -------- - > var prng = {{alias}}.PRNG; - - -{{alias}}.seed - Pseudorandom number generator seed. - - Examples - -------- - > var seed = {{alias}}.seed; - - -{{alias}}.seedLength - Length of generator seed. - - Examples - -------- - > var len = {{alias}}.seedLength; - - -{{alias}}.state - Generator state. - - Examples - -------- - > var out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Get a copy of the current state: - > var state = {{alias}}.state - - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - // Set the state: - > {{alias}}.state = state; - - // Regenerate a previous array: - > out = {{alias}}( [ 3, 3 ], 2.0, 5.0, 3.0 ) - - - -{{alias}}.stateLength - Length of generator state. - - Examples - -------- - > var len = {{alias}}.stateLength; - - -{{alias}}.byteLength - Size (in bytes) of generator state. - - Examples - -------- - > var sz = {{alias}}.byteLength; - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4d890b0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,442 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable space-in-parens */ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import random = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - random( [ 3, 3 ], 2.0, 5.0, 3.0, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array of numbers... -{ - random( '5', 2.0, 5.0, 3.0 ); // $ExpectError - random( true, 2.0, 5.0, 3.0 ); // $ExpectError - random( false, 2.0, 5.0, 3.0 ); // $ExpectError - random( null, 2.0, 5.0, 3.0 ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - random( {}, 2.0, 5.0, 3.0 ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - random( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - random( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( null, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - random( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - random( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or ndarray... -{ - random( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - random( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], null, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - random( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, null, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number or ndarray... -{ - random( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - random( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, null, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not a valid object... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, '5' ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, 5 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, true ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, false ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, [] ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a supported data type... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `order` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `mode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `submode` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `readonly` option... -{ - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - random(); // $ExpectError - random( [ 3, 3 ] ); // $ExpectError - random( [ 3, 3 ], 2.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - random( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} - -// Attached to the main export is an `assign` method which returns an ndarray... -{ - const arr = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - - random.assign( 2.0, 5.0, 3.0, arr ); // $ExpectType float64ndarray -} - -// The compiler throws an error if the `assign` method is provided a first argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( '5', 5.0, 3.0, arr ); // $ExpectError - random.assign( true, 5.0, 3.0, arr ); // $ExpectError - random.assign( false, 5.0, 3.0, arr ); // $ExpectError - random.assign( null, 5.0, 3.0, arr ); // $ExpectError - random.assign( [], 5.0, 3.0, arr ); // $ExpectError - random.assign( {}, 5.0, 3.0, arr ); // $ExpectError - random.assign( ( x: number ): number => x, 5.0, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a second argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, '5', 3.0, arr ); // $ExpectError - random.assign( 2.0, true, 3.0, arr ); // $ExpectError - random.assign( 2.0, false, 3.0, arr ); // $ExpectError - random.assign( 2.0, null, 3.0, arr ); // $ExpectError - random.assign( 2.0, [], 3.0, arr ); // $ExpectError - random.assign( 2.0, {}, 3.0, arr ); // $ExpectError - random.assign( 2.0, ( x: number ): number => x, 3.0, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not a number or ndarray... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign( 2.0, 5.0, '5', arr ); // $ExpectError - random.assign( 2.0, 5.0, true, arr ); // $ExpectError - random.assign( 2.0, 5.0, false, arr ); // $ExpectError - random.assign( 2.0, 5.0, null, arr ); // $ExpectError - random.assign( 2.0, 5.0, [], arr ); // $ExpectError - random.assign( 2.0, 5.0, {}, arr ); // $ExpectError - random.assign( 2.0, 5.0, ( x: number ): number => x, arr ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a fourth argument which is not an ndarray... -{ - random.assign( 2.0, 5.0, 3.0, '5' ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, true ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, false ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, null ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, [ '1' ] ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, {} ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const arr = zeros( [ 3, 3 ] ); - - random.assign(); // $ExpectError - random.assign( 2.0 ); // $ExpectError - random.assign( 2.0, 5.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0 ); // $ExpectError - random.assign( 2.0, 5.0, 3.0, arr, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - random.factory(); // $ExpectType RandomFunction - random.factory( { 'copy': false } ); // $ExpectType RandomFunction -} - -// The `factory` method returns a function which returns an ndarray... -{ - const fcn1 = random.factory(); - fcn1( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray - - const fcn2 = random.factory( {} ); - fcn2( [ 3, 3 ], 2.0, 5.0, 3.0 ); // $ExpectType RandomArray -} - -// The compiler throws an error if the `factory` method is provided an invalid argument... -{ - random.factory( '5' ); // $ExpectError - random.factory( true ); // $ExpectError - random.factory( false ); // $ExpectError - random.factory( [] ); // $ExpectError - random.factory( null ); // $ExpectError - random.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `prng` option which is not a pseudorandom number generator... -{ - random.factory( { 'prng': 123 } ); // $ExpectError - random.factory( { 'prng': 'abc' } ); // $ExpectError - random.factory( { 'prng': null } ); // $ExpectError - random.factory( { 'prng': [] } ); // $ExpectError - random.factory( { 'prng': {} } ); // $ExpectError - random.factory( { 'prng': true } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `seed` option which is not a valid seed... -{ - random.factory( { 'seed': true } ); // $ExpectError - random.factory( { 'seed': 'abc' } ); // $ExpectError - random.factory( { 'seed': null } ); // $ExpectError - random.factory( { 'seed': [ 'a' ] } ); // $ExpectError - random.factory( { 'seed': {} } ); // $ExpectError - random.factory( { 'seed': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `state` option which is not a valid state... -{ - random.factory( { 'state': 123 } ); // $ExpectError - random.factory( { 'state': 'abc' } ); // $ExpectError - random.factory( { 'state': null } ); // $ExpectError - random.factory( { 'state': [] } ); // $ExpectError - random.factory( { 'state': {} } ); // $ExpectError - random.factory( { 'state': true } ); // $ExpectError - random.factory( { 'state': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `copy` option which is not a boolean... -{ - random.factory( { 'copy': 123 } ); // $ExpectError - random.factory( { 'copy': 'abc' } ); // $ExpectError - random.factory( { 'copy': null } ); // $ExpectError - random.factory( { 'copy': [] } ); // $ExpectError - random.factory( { 'copy': {} } ); // $ExpectError - random.factory( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided more than one argument... -{ - random.factory( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = random.factory(); - fcn1( true, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0 ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0 ); // $ExpectError - - fcn1( true, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( false, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( '5', 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ '1' ], 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( {}, 2.0, 5.0, 3.0, {} ); // $ExpectError - fcn1( ( x: number ): number => x, 2.0, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], true, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], false, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], '5', 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], [], 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], {}, 5.0, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], ( x: number ): number => x, 5.0, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0 ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0 ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, true, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, false, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, '5', 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, [], 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, {}, 3.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, ( x: number ): number => x, 3.0, {} ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5' ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [] ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x ); // $ExpectError - - fcn1( [ 3, 3 ], 2.0, 5.0, true, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, false, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, '5', {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, [], {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, {}, {} ); // $ExpectError - fcn1( [ 3, 3 ], 2.0, 5.0, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided a `dtype` option which is not a supported data type... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `order` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `mode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `submode` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': [ '1' ] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid `readonly` option... -{ - const fcn = random.factory(); - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 123 } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': 'abc' } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': null } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': [] } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': {} } ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const fcn = random.factory(); - fcn(); // $ExpectError - fcn( [ 3, 3 ] ); // $ExpectError - fcn( [ 3, 3 ], 2.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0 ); // $ExpectError - fcn( [ 3, 3 ], 2.0, 5.0, 3.0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7883b41..0000000 --- a/examples/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 logEach = require( '@stdlib/console-log-each' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var triangular = require( './../lib' ); - -// Create a function for generating random arrays originating from the same state: -var random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate 3 one-dimensional arrays: -var x1 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x2 = random( [ 5 ], 2.0, 5.0, 3.0 ); -var x3 = random( [ 5 ], 2.0, 5.0, 3.0 ); - -// Print the contents: -logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) ); - -// Create another function for generating random arrays with the original state: -random = triangular.factory({ - 'state': triangular.state, - 'copy': true -}); - -// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence: -var x4 = random( [ 3, 5 ], 2.0, 5.0, 3.0 ); - -// Convert to a list of nested arrays: -var arr = ndarray2array( x4 ); - -// Print the contents: -console.log( '' ); -logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index dcbe765..e891f45 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { RealFloatingPointAndGenericDataType as DataType, floatndarray, typedndarray, genericndarray, Order, Mode, Shape } from '@stdlib/types/ndarray'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4685e19 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-ternary-factory@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.4.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";var s=n(t,[r("real_and_generic"),r("real_and_generic"),r("real_and_generic")],r("real_floating_point_and_generic"),{output:"real_floating_point_and_generic"}),i=s();e(i,"factory",s);const{assign:a}=i;export{a as assign,i as default,s as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bec81c4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/factory.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 createFactory from '@stdlib/random-tools-ternary-factory';\nimport dtypes from '@stdlib/ndarray-dtypes';\nimport base from '@stdlib/random-base-triangular';\n\n\n// VARIABLES //\n\nvar idtypes1 = dtypes( 'real_and_generic' );\nvar idtypes2 = dtypes( 'real_and_generic' );\nvar idtypes3 = dtypes( 'real_and_generic' );\nvar odtypes = dtypes( 'real_floating_point_and_generic' );\nvar policies = {\n\t'output': 'real_floating_point_and_generic'\n};\n\n\n// MAIN //\n\n/**\n* Returns a function for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @name factory\n* @type {Function}\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating ndarrays\n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var rand = factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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 factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns pseudorandom numbers drawn from a triangular distribution.\n*\n* @name triangular\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output ndarray shape\n* @param {(number|ndarrayLike)} a - minimum support\n* @param {(number|ndarrayLike)} b - maximum support\n* @param {(number|ndarrayLike)} c - mode\n* @param {Options} [options] - options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order=\"row-major\"] - memory layout (either row-major or column-major)\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only\n* @throws {TypeError} first argument must be a valid shape\n* @throws {TypeError} must provide valid distribution parameters\n* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndarray} output ndarray\n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\nvar triangular = factory();\n\n\n// EXPORTS //\n\nexport default triangular;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2026 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* Generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-triangular\n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 );\n* // returns \n*\n* @example\n* import triangular from '@stdlib/random-triangular';\n*\n* var rand = triangular.factory();\n* // returns \n*\n* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, {\n* 'dtype': 'generic'\n* });\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"assign\": \"main.assign\", \"factory\": \"main.factory\" }\n"],"names":["factory","createFactory","base","dtypes","output","triangular","setReadOnly","main"],"mappings":";;yZA6BA,IA0CIA,EAAUC,EAAeC,EAAM,CA1CpBC,EAAQ,oBACRA,EAAQ,oBACRA,EAAQ,qBACTA,EAAQ,mCACP,CACdC,OAAU,oCCyBPC,EAAaL,ICUjBM,EAAAC,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 316e2de..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( '@stdlib/random-tools-ternary-factory' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var base = require( '@stdlib/random-base-triangular' ); - - -// VARIABLES // - -var idtypes1 = dtypes( 'real_and_generic' ); -var idtypes2 = dtypes( 'real_and_generic' ); -var idtypes3 = dtypes( 'real_and_generic' ); -var odtypes = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; - - -// MAIN // - -/** -* Returns a function for generating pseudorandom numbers drawn from a triangular distribution. -* -* @name factory -* @type {Function} -* @param {Options} [options] - function options -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {Function} function for creating ndarrays -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var rand = factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var factory = createFactory( base, [ idtypes1, idtypes2, idtypes3 ], odtypes, policies ); // eslint-disable-line max-len - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9d381ac..0000000 --- a/lib/index.js +++ /dev/null @@ -1,77 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Generate pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-triangular -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var triangular = require( '@stdlib/random-triangular' ); -* -* var rand = triangular.factory(); -* // returns -* -* var arr = rand( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "assign": "main.assign", "factory": "main.factory" } diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 74a0457..0000000 --- a/lib/main.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns pseudorandom numbers drawn from a triangular distribution. -* -* @name triangular -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output ndarray shape -* @param {(number|ndarrayLike)} a - minimum support -* @param {(number|ndarrayLike)} b - maximum support -* @param {(number|ndarrayLike)} c - mode -* @param {Options} [options] - options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order="row-major"] - memory layout (either row-major or column-major) -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode=[options.mode]] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid distribution parameters -* @throws {TypeError} distribution parameters and the desired shape must be broadcast compatible -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndarray} output ndarray -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0 ); -* // returns -* -* @example -* var arr = triangular( [ 10 ], 2.0, 5.0, 3.0, { -* 'dtype': 'generic' -* }); -* // returns -*/ -var triangular = factory(); - - -// EXPORTS // - -module.exports = triangular; diff --git a/package.json b/package.json index 5735fd8..0270f16 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Generate pseudorandom numbers drawn from a triangular distribution.", "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,60 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/random-tools-ternary-factory": "^0.1.1", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-filled": "^0.3.1", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-same-float64array": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/console-log-each": "^0.2.4", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-cbrt": "^0.2.3", - "@stdlib/math-base-special-floor": "^0.2.4", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/math-base-special-sqrt": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-data-buffer": "^0.2.3", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-numel": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-orders": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "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.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b430c56 --- /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.assign.js b/test/test.assign.js deleted file mode 100644 index 0449cd7..0000000 --- a/test/test.assign.js +++ /dev/null @@ -1,314 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the `assign` method throws an error if provided a third argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided distribution parameters and the output array are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - zeros( [ 4, 4, 4 ] ), - zeros( [ 3, 3, 3, 3 ] ), - zeros( [ 1, 2, 3, 4 ] ), - zeros( [ 10, 10 ] ) - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( param1, param2, param3, value ); - }; - } -}); - -tape( 'the `assign` method throws an error if provided a read-only output array', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 3, 3 ], { - 'readonly': true - }) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random.assign( PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dimensional ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 3, 3 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcasted ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - out = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - out.set( 0, 0, NaN ); - - original = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - original.set( 0, 0, NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)', function test( t ) { - var original; - var actual; - var param1; - var param2; - var param3; - var out; - - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - out = zeros( [], { - 'dtype': 'float64' - }); - out.set( NaN ); - - original = zeros( [], { - 'dtype': 'float64' - }); - original.set( NaN ); - - actual = random.assign( param1, param2, param3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an output array has one or more dimensions of size zero, the `assign` method returns the output array unchanged', function test( t ) { - var original; - var actual; - var out; - - out = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - original = zeros( [ 2, 0, 2 ], { - 'dtype': 'float64' - }); - - actual = random.assign( PARAM1, PARAM2, PARAM3, out ); - - t.strictEqual( out, actual, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( getData( actual ), getData( original ) ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 54f985c..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isSameFloat64Array = require( '@stdlib/assert-is-same-float64array' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var factory = require( './../lib/factory.js' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - factory( value ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'state': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var random; - var values; - var i; - - random = factory(); - - values = [ - '5', - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( [ 2, 2 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var random; - var values; - var param1; - var param2; - var param3; - var i; - - random = factory(); - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var random; - var actual; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (row-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying the output array order (column-major; ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (scalar)', function test( t ) { - var random; - var actual; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var random; - var actual; - var param1; - var param2; - var param3; - var shape; - - random = factory(); - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying a PRNG seed', function test( t ) { - var random; - var arr1; - var arr2; - - random = factory({ - 'seed': 12345 - }); - arr1 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - random = factory({ - 'seed': 12345 - }); - arr2 = random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports specifying the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Create another function using the captured state: - random = factory({ - 'state': state - }); - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which supports setting the generator state', function test( t ) { - var random; - var state; - var arr1; - var arr2; - var i; - - random = factory(); - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr2 ), getData( arr1 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the underlying PRNG', function test( t ) { - var random; - var actual; - var i; - - random = factory({ - 'prng': minstd.normalized - }); - actual = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - - for ( i = 0; i < actual.length; i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function supports providing a seeded underlying PRNG', function test( t ) { - var random1; - var random2; - var randu; - var seed; - var arr1; - var arr2; - - seed = 12345; - - randu = minstd.factory({ - 'seed': seed - }); - random1 = factory({ - 'prng': randu.normalized - }); - - randu = minstd.factory({ - 'seed': seed - }); - random2 = factory({ - 'prng': randu.normalized - }); - - t.notEqual( random1, random2, 'separate generators' ); - - arr1 = random1( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - arr2 = random2( [ 10 ], PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - t.strictEqual( isSameFloat64Array( getData( arr1 ), getData( arr2 ) ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the returned function is the underlying PRNG', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.PRNG, 'function', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.PRNG, minstd.normalized, 'has property' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (integer seed)', function test( t ) { - var random = factory({ - 'seed': 12345 - }); - t.strictEqual( isUint32Array( random.seed ), true, 'has property' ); - t.strictEqual( random.seed[ 0 ], 12345, 'equal to provided seed' ); - - random = factory({ - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( random.seed, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator seed (array seed)', function test( t ) { - var actual; - var rand; - var seed; - var i; - - seed = [ 1234, 5678 ]; - rand = factory({ - 'seed': seed - }); - - actual = rand.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - t.end(); -}); - -tape( 'attached to the returned function is the generator seed length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.seedLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.seedLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state', function test( t ) { - var random = factory(); - t.strictEqual( isUint32Array( random.state ), true, 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.state, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state length', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.stateLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.stateLength, null, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the returned function is the generator state size', function test( t ) { - var random = factory(); - t.strictEqual( typeof random.byteLength, 'number', 'has property' ); - - random = factory({ - 'prng': minstd.normalized - }); - t.strictEqual( random.byteLength, null, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3c0d916..0000000 --- a/test/test.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var random = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is an `assign` method', function test( t ) { - t.strictEqual( typeof random.assign, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof random.factory, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the underlying PRNG', function test( t ) { - t.strictEqual( typeof random.PRNG, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed', function test( t ) { - t.strictEqual( isUint32Array( random.seed ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator seed length', function test( t ) { - t.strictEqual( typeof random.seedLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state', function test( t ) { - t.strictEqual( isUint32Array( random.state ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state length', function test( t ) { - t.strictEqual( typeof random.stateLength, 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is the generator state size', function test( t ) { - t.strictEqual( typeof random.byteLength, 'number', 'returns expected value' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 385e6b1..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,883 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' ); -var array = require( '@stdlib/ndarray-array' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var numel = require( '@stdlib/ndarray-numel' ); -var random = require( './../lib' ); - - -// VARIABLES // - -var PARAM1 = 2.0; -var PARAM2 = 5.0; -var PARAM3 = 3.0; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof random, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid shape (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - null, - true, - false, - void 0, - NaN, - [ -1 ], - {}, - 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() { - random( value, PARAM1, PARAM2, PARAM3, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - true, - false, - void 0, - NaN, - [], - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'foo', - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - random( [ 3, 3 ], PARAM1, PARAM2, PARAM3, { - 'dtype': value - }); - }; - } -}); - -tape( 'the function throws an error if provided distribution parameters and the output array shape are not broadcast compatible', function test( t ) { - var values; - var param1; - var param2; - var param3; - var i; - - values = [ - [ 4, 4, 4 ], - [ 3, 3, 3, 3 ], - [ 1, 2, 3, 4 ], - [ 10, 10 ] - ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - random( value, param1, param2, param3 ); - }; - } -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function returns an ndarray containing pseudorandom numbers (default; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=float64; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - var i; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ], [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ], [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ], [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array data type (dtype=generic; broadcasted ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - var i; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - for ( i = 0; i < numel( actual ); i++ ) { - t.strictEqual( isnan( actual.iget( i ) ), false, 'returns expected value for index '+i ); - } - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (row-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'row-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'row-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying the output array order (column-major; ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'order': 'column-major' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( getOrder( actual ), 'column-major', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (scalar)', function test( t ) { - var actual; - var shape; - - shape = [ 3, 3 ]; - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 3, 3 ]; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports specifying whether the output array is read-only (ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = [ 2, 2 ]; - param1 = array( [ [ PARAM1, PARAM1 ] ] ); - param2 = array( [ [ PARAM2, PARAM2 ] ] ); - param3 = array( [ [ PARAM3, PARAM3 ] ] ); - - actual = random( shape, param1, param2, param3, { - 'readonly': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - - actual = random( shape, param1, param2, param3, { - 'readonly': true - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (default; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=float64; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'float64', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'float64', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'float64', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; scalar)', function test( t ) { - var actual; - var shape; - - shape = []; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty shape, the function returns a zero-dimensional ndarray (dtype=generic; zero-dimensional ndarray)', function test( t ) { - var actual; - var param1; - var param2; - var param3; - var shape; - - shape = []; - param1 = scalar2ndarray( PARAM1, 'generic', 'row-major' ); - param2 = scalar2ndarray( PARAM2, 'generic', 'row-major' ); - param3 = scalar2ndarray( PARAM3, 'generic', 'row-major' ); - actual = random( shape, param1, param2, param3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( typeof actual.get(), 'number', 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (default)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=float64)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'float64' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a shape having one or more dimensions of size zero, the function returns an empty array (dtype=generic)', function test( t ) { - var actual; - var shape; - - shape = [ 2, 0, 2 ]; - actual = random( shape, PARAM1, PARAM2, PARAM3, { - 'dtype': 'generic' - }); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); - t.deepEqual( getShape( actual ), shape, 'returns expected value' ); - - t.strictEqual( numel( actual ), 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports setting the generator state', function test( t ) { - var state; - var arr1; - var arr2; - var i; - - // Move to a future state... - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Capture the current state: - state = random.state; - - // Move to a future state... - arr1 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - for ( i = 0; i < 100; i++ ) { - random( [ 2 ], PARAM1, PARAM2, PARAM3 ); - } - // Set the state: - random.state = state; - - // Replay previously generated values: - arr2 = random( [ 10 ], PARAM1, PARAM2, PARAM3 ); - t.deepEqual( getData( arr2 ), getData( arr1 ), 'returns expected value' ); - - t.end(); -});