From 68d4b7ffe41e702223010b6661371912d479895e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 May 2025 02:19:02 +0000 Subject: [PATCH 01/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index cb08e0b..a30dc0c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,7 +58,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -294,10 +294,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } for ( i = 0; i < idtypes.length; i++ ) { if ( @@ -316,7 +316,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); } if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -404,7 +404,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -547,7 +547,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index d93fe4c..478c78c 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -57,12 +57,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = options.dtype; if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 1adcf47..e927e61 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 32ff7f036459f149c06d91b7de4c9bb8f1d4463d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 13 May 2025 02:20:04 +0000 Subject: [PATCH 02/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 599 --- lib/validate.js | 87 - package.json | 95 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5449 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1fd8328..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var P=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var N=P(function(_r,A){"use strict";var U=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-has-own-property"),W=require("@stdlib/array-base-assert-contains"),X=require("@stdlib/array-base-join"),C=require("@stdlib/string-format");function Y(t,r,e){return U(e)?w(e,"dtype")&&(t.dtype=e.dtype,!W(r,t.dtype))?new TypeError(C('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",X(r,'", "'),t.dtype)):(w(e,"order")&&(t.order=e.order),w(e,"mode")&&(t.mode=e.mode),w(e,"submode")&&(t.submode=e.submode),w(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(C("invalid argument. Options argument must be an object. Value: `%s`.",e))}A.exports=Y});var Q=P(function(jr,M){"use strict";var I=require("@stdlib/utils-define-nonenumerable-read-only-property"),Z=require("@stdlib/assert-is-nonnegative-integer-array").primitives,$=require("@stdlib/assert-is-empty-collection"),V=require("@stdlib/assert-is-ndarray-like"),G=require("@stdlib/assert-is-number").isPrimitive,rr=require("@stdlib/assert-is-function"),z=require("@stdlib/assert-is-complex-like"),er=require("@stdlib/assert-is-plain-object"),ar=require("@stdlib/assert-is-object"),_=require("@stdlib/assert-is-collection"),R=require("@stdlib/ndarray-base-assert-is-data-type"),tr=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),ir=require("@stdlib/ndarray-base-assert-is-read-only"),nr=require("@stdlib/ndarray-base-assert-is-order"),ur=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),or=require("@stdlib/array-base-filled-by"),B=require("@stdlib/array-base-every-by"),D=require("@stdlib/array-base-join"),lr=require("@stdlib/strided-base-nullary"),H=require("@stdlib/ndarray-base-binary"),J=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),vr=require("@stdlib/ndarray-base-binary-output-dtype"),sr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),dr=require("@stdlib/ndarray-shape"),F=require("@stdlib/ndarray-dtype"),K=require("@stdlib/ndarray-order"),fr=require("@stdlib/ndarray-ndims"),S=require("@stdlib/ndarray-ctor"),gr=require("@stdlib/ndarray-defaults"),yr=require("@stdlib/array-base-assert-is-accessor-array"),mr=require("@stdlib/array-base-accessor-setter"),cr=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),hr=N(),k=["First","Second","Third"];function pr(t){var r,e,a,n;for(r=[],n=0;n4){if(!er(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(ur(n,"order")&&(i.order=n.order,!nr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}I(h.prototype,"generate",function(r,e,a,n){var i,v,d,o,u,l,g,q,E,O,s,y,c,p,m;if(!Z(r)&&!$(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(d={},arguments.length>3&&(u=hr(d,this._odtypes,n),u))throw u;for(i=pr([e,a]),m=0;m} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,Q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AAI,EACpB+B,EAAM5C,EAAUa,CAAI,EACf,CAAC1B,EAAU,KAAK,SAAUyD,CAAI,EAClC,MAAM,IAAI,UAAWpC,EAAQ,kGAAmGE,EAAU,CAAE,EAAGpB,EAAM,KAAK,SAAU,MAAO,EAAGsD,CAAI,CAAE,EAGrL,IADAhC,EAAS,CAAEmB,EAAQC,CAAO,EACpBhB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGTxC,EAAUsC,CAAE,GAEhB6B,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1B7C,EAAeoC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BhD,EAAeuC,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIrB,EAAWqB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACpC,EAAU,KAAK,SAAU6B,CAAE,EAAG2B,CAAI,EACvC,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG1B,EAAM,KAAK,SAAU0B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBrB,EAAQoB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD1C,EAAO,QAAUqD,IC7gBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "param1", "param2", "buf", "err", "len", "FLG", "set", "dt", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6056c2c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3b308c2..0be3435 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6e28c57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAAQ,gFAAiFV,IAE/G,IAAMc,EAAUb,GACf,MAAM,IAAIQ,UAAWC,EAAQ,SAAUT,IAExC,IAAMc,EAAwBd,EAASe,QACtC,MAAM,IAAIP,UAAWC,EAAQ,+GAAgHT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,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a30dc0c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,599 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = getDType( p ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {StringArray} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - for ( i = 0; i < idtypes.length; i++ ) { - if ( - !isCollection( idtypes[ i ] ) || - idtypes[ i ].length < 1 || - !everyBy( idtypes[ i ], isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], dt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( dt === 'generic' ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} second argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, odt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], pdt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 478c78c..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {StringArray} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {string} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = options.dtype; - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e927e61..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,74 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2745412 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index b68e30a..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From c75686f85a77a1127473e191ce24c9b641e5fce0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 00:42:55 +0000 Subject: [PATCH 03/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index cb08e0b..a30dc0c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,7 +58,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -294,10 +294,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } for ( i = 0; i < idtypes.length; i++ ) { if ( @@ -316,7 +316,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); } if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -404,7 +404,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -547,7 +547,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index d93fe4c..478c78c 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -57,12 +57,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = options.dtype; if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 1adcf47..e927e61 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From bfd4fb3fde5ade83a002719e2e98eaa7987461ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 01:01:27 +0000 Subject: [PATCH 04/45] Remove files --- index.d.ts | 324 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5171 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 0be3435..0000000 --- a/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6e28c57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAAQ,gFAAiFV,IAE/G,IAAMc,EAAUb,GACf,MAAM,IAAIQ,UAAWC,EAAQ,SAAUT,IAExC,IAAMc,EAAwBd,EAASe,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IiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2745412..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30706796c0fd515b33c7d09e51e4df374711ce01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 01:02:09 +0000 Subject: [PATCH 05/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 599 --- lib/validate.js | 87 - package.json | 95 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5450 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 83246e5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-19T00:41:33.216Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1fd8328..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var P=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var N=P(function(_r,A){"use strict";var U=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-has-own-property"),W=require("@stdlib/array-base-assert-contains"),X=require("@stdlib/array-base-join"),C=require("@stdlib/string-format");function Y(t,r,e){return U(e)?w(e,"dtype")&&(t.dtype=e.dtype,!W(r,t.dtype))?new TypeError(C('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",X(r,'", "'),t.dtype)):(w(e,"order")&&(t.order=e.order),w(e,"mode")&&(t.mode=e.mode),w(e,"submode")&&(t.submode=e.submode),w(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(C("invalid argument. Options argument must be an object. Value: `%s`.",e))}A.exports=Y});var Q=P(function(jr,M){"use strict";var I=require("@stdlib/utils-define-nonenumerable-read-only-property"),Z=require("@stdlib/assert-is-nonnegative-integer-array").primitives,$=require("@stdlib/assert-is-empty-collection"),V=require("@stdlib/assert-is-ndarray-like"),G=require("@stdlib/assert-is-number").isPrimitive,rr=require("@stdlib/assert-is-function"),z=require("@stdlib/assert-is-complex-like"),er=require("@stdlib/assert-is-plain-object"),ar=require("@stdlib/assert-is-object"),_=require("@stdlib/assert-is-collection"),R=require("@stdlib/ndarray-base-assert-is-data-type"),tr=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),ir=require("@stdlib/ndarray-base-assert-is-read-only"),nr=require("@stdlib/ndarray-base-assert-is-order"),ur=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),or=require("@stdlib/array-base-filled-by"),B=require("@stdlib/array-base-every-by"),D=require("@stdlib/array-base-join"),lr=require("@stdlib/strided-base-nullary"),H=require("@stdlib/ndarray-base-binary"),J=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),vr=require("@stdlib/ndarray-base-binary-output-dtype"),sr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),dr=require("@stdlib/ndarray-shape"),F=require("@stdlib/ndarray-dtype"),K=require("@stdlib/ndarray-order"),fr=require("@stdlib/ndarray-ndims"),S=require("@stdlib/ndarray-ctor"),gr=require("@stdlib/ndarray-defaults"),yr=require("@stdlib/array-base-assert-is-accessor-array"),mr=require("@stdlib/array-base-accessor-setter"),cr=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),hr=N(),k=["First","Second","Third"];function pr(t){var r,e,a,n;for(r=[],n=0;n4){if(!er(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(ur(n,"order")&&(i.order=n.order,!nr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}I(h.prototype,"generate",function(r,e,a,n){var i,v,d,o,u,l,g,q,E,O,s,y,c,p,m;if(!Z(r)&&!$(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(d={},arguments.length>3&&(u=hr(d,this._odtypes,n),u))throw u;for(i=pr([e,a]),m=0;m} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,EAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMR,EAAUQ,CAAQ,EAGnBP,EAAYO,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,MAChB,CAACN,EAAUK,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASD,EAAMI,EAAQ,MAAO,EAAGD,EAAK,KAAM,CAAE,GAI1JL,EAAYO,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBP,EAAYO,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBP,EAAYO,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAAQ,SAEnBP,EAAYO,EAAS,UAAW,IACpCF,EAAK,SAAWE,EAAQ,UAElB,MArBC,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,CAsBhH,CAKAT,EAAO,QAAUM,ICtFjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,c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,KAAK,SAAU6B,CAAE,EAAG2B,CAAI,EACvC,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG1B,EAAM,KAAK,SAAU0B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBrB,EAAQoB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD1C,EAAO,QAAUqD,IC7gBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "param1", "param2", "buf", "err", "len", "FLG", "set", "dt", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6056c2c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3b308c2..0be3435 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6e28c57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EA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D,EAEJ,IAAM0D,EAAevB,GACpB,MAAM,IAAI9B,UAAWC,EAAQ,gFAAiF6B,IAE/G,GAAKkD,EAAYlD,GAChB,MAAM,IAAImD,MAAOhF,EAAO,WAKzB,GAHA8E,EAAKG,EAAUpD,GACfF,EAAM2B,EAAUzB,GAChBgD,EAAMxB,EAAUxB,IACVS,EAAU3C,KAAKoB,SAAU8D,GAC9B,MAAM,IAAI9E,UAAWC,EAAQ,kGAAmGd,EAAU,GAAKqD,EAAM5C,KAAKoB,SAAU,QAAU8D,IAG/K,IADAtD,EAAS,CAAEF,EAAQC,GACb5B,EAAI,EAAGA,EAAI6B,EAAO1B,OAAQH,IAAM,CAyBrC,GAxBAkD,EAAIrB,EAAQ7B,GAGPuD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a30dc0c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,599 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = getDType( p ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {StringArray} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - for ( i = 0; i < idtypes.length; i++ ) { - if ( - !isCollection( idtypes[ i ] ) || - idtypes[ i ].length < 1 || - !everyBy( idtypes[ i ], isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], dt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( dt === 'generic' ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} second argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, odt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], pdt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 478c78c..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {StringArray} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {string} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = options.dtype; - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e927e61..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,74 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2745412 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index b68e30a..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.equal( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From abc903c95c629065a0cc9fbc9e06d0961a839d44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:12:10 +0000 Subject: [PATCH 06/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7fcfeed..98920de 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,7 +58,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -294,10 +294,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } for ( i = 0; i < idtypes.length; i++ ) { if ( @@ -316,7 +316,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); } if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -404,7 +404,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -547,7 +547,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index d93fe4c..478c78c 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -57,12 +57,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = options.dtype; if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 1adcf47..e927e61 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 58da05cd5bbb75fef7b79399208760ae830622d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:12:29 +0000 Subject: [PATCH 07/45] Remove files --- index.d.ts | 324 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5171 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 0be3435..0000000 --- a/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6e28c57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} second argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,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IN,EACAqD,EACAC,EACAlD,EACAmD,EACAlC,EACAlD,EAEJ,IAAM0D,EAAevB,GACpB,MAAM,IAAI9B,UAAWC,EAAQ,gFAAiF6B,IAE/G,GAAKkD,EAAYlD,GAChB,MAAM,IAAImD,MAAOhF,EAAO,WAKzB,GAHA8E,EAAKG,EAAUpD,GACfF,EAAM2B,EAAUzB,GAChBgD,EAAMxB,EAAUxB,IACVS,EAAU3C,KAAKoB,SAAU8D,GAC9B,MAAM,IAAI9E,UAAWC,EAAQ,kGAAmGd,EAAU,GAAKqD,EAAM5C,KAAKoB,SAAU,QAAU8D,IAG/K,IADAtD,EAAS,CAAEF,EAAQC,GACb5B,EAAI,EAAGA,EAAI6B,EAAO1B,OAAQH,IAAM,CAyBrC,GAxBAkD,EAAIrB,EAAQ7B,GAGPuD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2745412..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5f43d4a73aa6634c43ce25963676debe2880ddb7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:13:24 +0000 Subject: [PATCH 08/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 51 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 599 --- lib/validate.js | 87 - package.json | 95 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5457 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1fd8328..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var P=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var N=P(function(_r,A){"use strict";var U=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-has-own-property"),W=require("@stdlib/array-base-assert-contains"),X=require("@stdlib/array-base-join"),C=require("@stdlib/string-format");function Y(t,r,e){return U(e)?w(e,"dtype")&&(t.dtype=e.dtype,!W(r,t.dtype))?new TypeError(C('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",X(r,'", "'),t.dtype)):(w(e,"order")&&(t.order=e.order),w(e,"mode")&&(t.mode=e.mode),w(e,"submode")&&(t.submode=e.submode),w(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(C("invalid argument. Options argument must be an object. Value: `%s`.",e))}A.exports=Y});var Q=P(function(jr,M){"use strict";var I=require("@stdlib/utils-define-nonenumerable-read-only-property"),Z=require("@stdlib/assert-is-nonnegative-integer-array").primitives,$=require("@stdlib/assert-is-empty-collection"),V=require("@stdlib/assert-is-ndarray-like"),G=require("@stdlib/assert-is-number").isPrimitive,rr=require("@stdlib/assert-is-function"),z=require("@stdlib/assert-is-complex-like"),er=require("@stdlib/assert-is-plain-object"),ar=require("@stdlib/assert-is-object"),_=require("@stdlib/assert-is-collection"),R=require("@stdlib/ndarray-base-assert-is-data-type"),tr=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),ir=require("@stdlib/ndarray-base-assert-is-read-only"),nr=require("@stdlib/ndarray-base-assert-is-order"),ur=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),or=require("@stdlib/array-base-filled-by"),B=require("@stdlib/array-base-every-by"),D=require("@stdlib/array-base-join"),lr=require("@stdlib/strided-base-nullary"),H=require("@stdlib/ndarray-base-binary"),J=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),vr=require("@stdlib/ndarray-base-binary-output-dtype"),sr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),dr=require("@stdlib/ndarray-shape"),F=require("@stdlib/ndarray-dtype"),K=require("@stdlib/ndarray-order"),fr=require("@stdlib/ndarray-ndims"),S=require("@stdlib/ndarray-ctor"),gr=require("@stdlib/ndarray-defaults"),yr=require("@stdlib/array-base-assert-is-accessor-array"),mr=require("@stdlib/array-base-accessor-setter"),cr=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),hr=N(),k=["First","Second","Third"];function pr(t){var r,e,a,n;for(r=[],n=0;n4){if(!er(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(ur(n,"order")&&(i.order=n.order,!nr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}I(h.prototype,"generate",function(r,e,a,n){var i,v,d,o,u,l,g,q,E,O,s,y,c,p,m;if(!Z(r)&&!$(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(d={},arguments.length>3&&(u=hr(d,this._odtypes,n),u))throw u;for(i=pr([e,a]),m=0;m} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,EAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMR,EAAUQ,CAAQ,EAGnBP,EAAYO,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,MAChB,CAACN,EAAUK,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASD,EAAMI,EAAQ,MAAO,EAAGD,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GAEhB6B,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1B7C,EAAeoC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BhD,EAAeuC,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIrB,EAAWqB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACpC,EAAU,KAAK,SAAU6B,CAAE,EAAG2B,CAAI,EACvC,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG1B,EAAM,KAAK,SAAU0B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBrB,EAAQoB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD1C,EAAO,QAAUqD,IC7gBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "param1", "param2", "buf", "err", "len", "FLG", "set", "dt", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6056c2c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3b308c2..0be3435 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6e28c57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAAQ,gFAAiFV,IAE/G,IAAMc,EAAUb,GACf,MAAM,IAAIQ,UAAWC,EAAQ,SAAUT,IAExC,IAAMc,EAAwBd,EAASe,QACtC,MAAM,IAAIP,UAAWC,EAAQ,+GAAgHT,EAASe,SAKvJ,GAHAb,EAAO,CACNc,MAASC,EAASC,IAAK,UAEnBb,UAAUC,OAAS,EAAI,CAC3B,IAAMa,EAAelB,GACpB,MAAM,IAAIO,UAAWC,EAAQ,SAAUR,IAExC,GAAKmB,EAAYnB,EAAS,WACzBC,EAAKc,MAAQf,EAAQe,OACfK,EAASnB,EAAKc,QACnB,MAAM,IAAIR,UAAWC,EAAQ,2EAA4E,QAASP,EAAKc,OAGzH,CAQD,OAPAZ,KAAKkB,MAAQzB,EACbO,KAAKmB,SAAW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AK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 98920de..0000000 --- a/lib/main.js +++ /dev/null @@ -1,599 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = getDType( p ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {StringArray} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - for ( i = 0; i < idtypes.length; i++ ) { - if ( - !isCollection( idtypes[ i ] ) || - idtypes[ i ].length < 1 || - !everyBy( idtypes[ i ], isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], dt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( dt === 'generic' ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, odt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], pdt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 478c78c..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {StringArray} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {string} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = options.dtype; - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e927e61..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,74 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..be0089a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c79201a..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From a0eb63ebbd27024c8ca9693e6aa34376fcab92fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:18:28 +0000 Subject: [PATCH 09/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7fcfeed..98920de 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,7 +58,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -294,10 +294,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } for ( i = 0; i < idtypes.length; i++ ) { if ( @@ -316,7 +316,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); } if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -404,7 +404,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -547,7 +547,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index d93fe4c..478c78c 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -57,12 +57,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = options.dtype; if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 1adcf47..e927e61 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From efc46b77f71d4bb2ea81de3d40d04eb3cf37d93b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:18:46 +0000 Subject: [PATCH 10/45] Remove files --- index.d.ts | 324 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5171 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 0be3435..0000000 --- a/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6e28c57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAAQ,gFAAiFV,IAE/G,IAAMc,EAAUb,GACf,MAAM,IAAIQ,UAAWC,EAAQ,SAAUT,IAExC,IAAMc,EAAwBd,EAASe,QACtC,MAAM,IAAIP,UAAWC,EAAQ,+GAAgHT,EAASe,SAKvJ,GAHAb,EAAO,CACNc,MAASC,EAASC,IAAK,UAEnBb,UAAUC,OAAS,EAAI,CAC3B,IAAMa,EAAelB,GACpB,MAAM,IAAIO,UAAWC,EAAQ,SAAUR,IAExC,GAAKmB,EAAYnB,EAAS,WACzBC,EAAKc,MAAQf,EAAQe,OACfK,EAASnB,EAAKc,QACnB,MAAM,IAAIR,UAAWC,EAAQ,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AAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index be0089a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df32f0c6998b3a5409a26177ec7d929127736294 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Dec 2025 02:19:12 +0000 Subject: [PATCH 11/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 599 --- lib/validate.js | 87 - package.json | 95 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5458 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1fd8328..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var P=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var N=P(function(_r,A){"use strict";var U=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-has-own-property"),W=require("@stdlib/array-base-assert-contains"),X=require("@stdlib/array-base-join"),C=require("@stdlib/string-format");function Y(t,r,e){return U(e)?w(e,"dtype")&&(t.dtype=e.dtype,!W(r,t.dtype))?new TypeError(C('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",X(r,'", "'),t.dtype)):(w(e,"order")&&(t.order=e.order),w(e,"mode")&&(t.mode=e.mode),w(e,"submode")&&(t.submode=e.submode),w(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(C("invalid argument. Options argument must be an object. Value: `%s`.",e))}A.exports=Y});var Q=P(function(jr,M){"use strict";var I=require("@stdlib/utils-define-nonenumerable-read-only-property"),Z=require("@stdlib/assert-is-nonnegative-integer-array").primitives,$=require("@stdlib/assert-is-empty-collection"),V=require("@stdlib/assert-is-ndarray-like"),G=require("@stdlib/assert-is-number").isPrimitive,rr=require("@stdlib/assert-is-function"),z=require("@stdlib/assert-is-complex-like"),er=require("@stdlib/assert-is-plain-object"),ar=require("@stdlib/assert-is-object"),_=require("@stdlib/assert-is-collection"),R=require("@stdlib/ndarray-base-assert-is-data-type"),tr=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),ir=require("@stdlib/ndarray-base-assert-is-read-only"),nr=require("@stdlib/ndarray-base-assert-is-order"),ur=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),or=require("@stdlib/array-base-filled-by"),B=require("@stdlib/array-base-every-by"),D=require("@stdlib/array-base-join"),lr=require("@stdlib/strided-base-nullary"),H=require("@stdlib/ndarray-base-binary"),J=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),vr=require("@stdlib/ndarray-base-binary-output-dtype"),sr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),dr=require("@stdlib/ndarray-shape"),F=require("@stdlib/ndarray-dtype"),K=require("@stdlib/ndarray-order"),fr=require("@stdlib/ndarray-ndims"),S=require("@stdlib/ndarray-ctor"),gr=require("@stdlib/ndarray-defaults"),yr=require("@stdlib/array-base-assert-is-accessor-array"),mr=require("@stdlib/array-base-accessor-setter"),cr=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),hr=N(),k=["First","Second","Third"];function pr(t){var r,e,a,n;for(r=[],n=0;n4){if(!er(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(ur(n,"order")&&(i.order=n.order,!nr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}I(h.prototype,"generate",function(r,e,a,n){var i,v,d,o,u,l,g,q,E,O,s,y,c,p,m;if(!Z(r)&&!$(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(d={},arguments.length>3&&(u=hr(d,this._odtypes,n),u))throw u;for(i=pr([e,a]),m=0;m} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EA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AO,6FAA8F,EAKhH,GAHAgC,EAAK9C,GAAUc,CAAI,EACnBU,EAAMtB,EAAUY,CAAI,EACpB+B,EAAM5C,EAAUa,CAAI,EACf,CAAC1B,EAAU,KAAK,SAAUyD,CAAI,EAClC,MAAM,IAAI,UAAWpC,EAAQ,kGAAmGE,EAAU,CAAE,EAAGpB,EAAM,KAAK,SAAU,MAAO,EAAGsD,CAAI,CAAE,EAGrL,IADAhC,EAAS,CAAEmB,EAAQC,CAAO,EACpBhB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGTxC,EAAUsC,CAAE,GAEhB6B,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1B7C,EAAeoC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BhD,EAAeuC,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIrB,EAAWqB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAIpB,EAAiBoB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACpC,EAAU,KAAK,SAAU6B,CAAE,EAAG2B,CAAI,EACvC,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG1B,EAAM,KAAK,SAAU0B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBrB,EAAQoB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD1C,EAAO,QAAUqD,IC7gBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "param1", "param2", "buf", "err", "len", "FLG", "set", "dt", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 6056c2c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3b308c2..0be3435 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6e28c57 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAAQ,gFAAiFV,IAE/G,IAAMc,EAAUb,GACf,MAAM,IAAIQ,UAAWC,EAAQ,SAA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7B,GAGPuD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 98920de..0000000 --- a/lib/main.js +++ /dev/null @@ -1,599 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = getDType( p ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {StringArray} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - for ( i = 0; i < idtypes.length; i++ ) { - if ( - !isCollection( idtypes[ i ] ) || - idtypes[ i ].length < 1 || - !everyBy( idtypes[ i ], isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {string} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], dt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( dt === 'generic' ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, odt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], pdt ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 478c78c..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {StringArray} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {string} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = options.dtype; - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), opts.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e927e61..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,74 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..be0089a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c79201a..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From c1eff8330a20dc9d54745e111c346659ad11f727 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Dec 2025 10:06:18 +0000 Subject: [PATCH 12/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index d0a01e3..98ad31c 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 3e07d4534e67b720d74be39a5dc15fa6f1d6a70b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Dec 2025 10:06:33 +0000 Subject: [PATCH 13/45] Remove files --- index.d.ts | 324 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5171 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 0be3435..0000000 --- a/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6e28c57..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var C=["First","Second","Third"];function G(e,t,r,s,n){var d,h;if(!(this instanceof G))return arguments.length<5?new G(e,t,r,s):new G(e,t,r,s,n);if(!i(e))throw new TypeError(B("null3c",e));if(!m(t))throw new TypeError(B("null2y",t));for(h=0;h4){if(!o(n))throw new TypeError(B("null2V",n));if(y(n,"order")&&(d.order=n.order,!j(d.order)))throw new TypeError(B("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(G.prototype,"generate",(function(e,i,a,m){var l,p,h,j,f,k,O,G,H,I,J,K,M,N;if(!t(e)&&!r(e))throw new TypeError(B("null5o",e));if(h={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=r.dtype,!v(t,e.dtype))?new TypeError(B("null4S","dtype",c(t,'", "'),e.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(B("null2V",r))}(h,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {StringArray} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tif (\n\t\t\t!isCollection( idtypes[ i ] ) ||\n\t\t\tidtypes[ i ].length < 1 ||\n\t\t\t!everyBy( idtypes[ i ], isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {string} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], dt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( dt === 'generic' ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, odt ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], pdt ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {StringArray} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {string} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = options.dtype;\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","i","this","arguments","length","isFunction","TypeError","format","isCollection","everyBy","isDataType","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","dt","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2jHAkEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACJ,KAAQC,gBAAgBR,GACvB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMM,EAAYV,GACjB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAExC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,SAAUX,IAExC,IAAMK,EAAI,EAAGA,EAAIL,EAAQQ,OAAQH,IAChC,IACEO,EAAcZ,EAASK,KACxBL,EAASK,GAAIG,OAAS,IACrBK,EAASb,EAASK,GAAKS,GAExB,MAAM,IAAIJ,UAAWC,EAAQ,oFAAqFX,IAGpH,IACEY,EAAcX,IACfA,EAAQO,OAAS,IAChBK,EAASZ,EAASa,GAEnB,MAAM,IAAIJ,UAAWC,EAA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AI,EAAGA,EAAI6B,EAAO1B,OAAQH,IAAM,CAyBrC,GAxBAkD,EAAIrB,EAAQ7B,GAGPuD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,GACtBuB,EAAeN,IAEzBgC,EADqB,IAAjBhC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGgC,EAAKE,EAAInD,IACtByB,EAAeR,IAE1BgC,EAAMvB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGkC,IAIlBlC,EAAIiB,EAAiBjB,EADrBgC,EAAM,UACuBE,EAAInD,IAE5BW,EAAU3C,KAAKmB,SAAUpB,GAAKkF,GACnC,MAAM,IAAI7E,UAAWC,EAAQ,kGAAmGd,EAAUQ,GAAK6C,EAAM5C,KAAKmB,SAAUpB,GAAK,QAAUkF,IAEpLrD,EAAQ7B,GAAMkD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb8C,EAAQpD,EAAQ5B,KAAKkB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index be0089a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1365bf19c9efd23bfb44caa4c086e9bd23c9d837 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Dec 2025 10:06:59 +0000 Subject: [PATCH 14/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 65 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5486 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,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,EAAMtB,EAAUY,CAAI,EACpB+B,EAAM5C,EAAUa,CAAI,EACf,CAAC7B,EAAU,KAAK,SAAUW,EAAYiD,CAAI,CAAE,EAChD,MAAM,IAAI,UAAWpC,EAAQ,kGAAmGE,EAAU,CAAE,EAAGvB,EAAM,KAAK,SAAU,MAAO,EAAGyD,CAAI,CAAE,EAGrL,IADAhC,EAAS,CAAEoB,EAAQC,CAAO,EACpBjB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGT5C,EAAU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3b308c2..0be3435 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..26028d6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(v(n,"order")&&(d.order=n.order,!y(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,y,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?v(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(v(r,"order")&&(e.order=r.order),v(r,"mode")&&(e.mode=r.mode),v(r,"submode")&&(e.submode=r.submode),v(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;u8HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAA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EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 98ad31c..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-equal-data-type": "github:stdlib-js/ndarray-base-assert-is-equal-data-type#main", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.2.2", - "@stdlib/ndarray-base-dtypes2strings": "github:stdlib-js/ndarray-base-dtypes2strings#main", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9ca6045 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 1c20230ee6298c87f2fd02b7573c2feaac4dd732 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 Jan 2026 04:39:14 +0000 Subject: [PATCH 15/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index d0a01e3..98ad31c 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 8f3e45e5fab6853cf31ea2f348871ec658584743 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 Jan 2026 04:39:31 +0000 Subject: [PATCH 16/45] Remove files --- index.d.ts | 324 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5171 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 0be3435..0000000 --- a/index.d.ts +++ /dev/null @@ -1,324 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 26028d6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(v(n,"order")&&(d.order=n.order,!y(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,y,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?v(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(v(r,"order")&&(e.order=r.order),v(r,"mode")&&(e.mode=r.mode),v(r,"submode")&&(e.submode=r.submode),v(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;u8HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,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,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9ca6045..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 47bcbd8198e6d8319de2d7e1a6e40830780ff196 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 12 Jan 2026 04:40:08 +0000 Subject: [PATCH 17/45] 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 | 66 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5587 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBR,EAAYQ,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBR,EAAYQ,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAA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EACpBjB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGT5C,EAAU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e4c050f --- /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@esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=v(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(u(n,"order")&&(d.order=n.order,!y(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,y,g,v,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(g=function(e,t,r){return o(r)?u(r,"dtype")&&(e.dtype=k(r.dtype),!c(t,e.dtype))?new TypeError(I("null4S","dtype",b(t,'", "'),r.dtype)):(u(r,"order")&&(e.order=r.order),u(r,"mode")&&(e.mode=r.mode),u(r,"submode")&&(e.submode=r.submode),u(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),g))throw g;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2sHAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACXM,EAASV,EAAIW,GAEd,MAAM,IAAIL,UAAWC,EAAQ,oFAAqFZ,IAEnHA,EAASM,GAAMW,EAAgBZ,EAC/B,CACD,IACEQ,EAAcZ,IACfA,EAAQQ,OAAS,IAChBM,EAASd,EAASe,GAEnB,MAAM,IAAIL,UAAWC,EAAQ,gFAAiFX,IAI/G,GAFAA,EAAUgB,EAAg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AAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 98ad31c..2e1cb3f 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-equal-data-type": "github:stdlib-js/ndarray-base-assert-is-equal-data-type#main", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "github:stdlib-js/ndarray-base-assert-is-output-data-type-policy#main", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "github:stdlib-js/ndarray-base-binary#main", - "@stdlib/ndarray-base-binary-output-dtype": "github:stdlib-js/ndarray-base-binary-output-dtype#main", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.2.2", - "@stdlib/ndarray-base-dtypes2strings": "github:stdlib-js/ndarray-base-dtypes2strings#main", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..40de85b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 32269c4acabc1f2fd12be81524c29e6f73a2bfc6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 06:59:11 +0000 Subject: [PATCH 18/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index ef4bf8b..f492141 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From d83caf8508fbfe11944b64e3aa89e5d87d2e926c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:03:14 +0000 Subject: [PATCH 19/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e4c050f..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@esm/index.mjs";import{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=v(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(u(n,"order")&&(d.order=n.order,!y(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,y,g,v,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(g=function(e,t,r){return o(r)?u(r,"dtype")&&(e.dtype=k(r.dtype),!c(t,e.dtype))?new TypeError(I("null4S","dtype",b(t,'", "'),r.dtype)):(u(r,"order")&&(e.order=r.order),u(r,"mode")&&(e.mode=r.mode),u(r,"submode")&&(e.submode=r.submode),u(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),g))throw g;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;2sHAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACXM,EAASV,EAAIW,GAEd,MAAM,IAAIL,UAAWC,EAAQ,oFAAqFZ,IAEnHA,EAASM,GAAMW,EAAgBZ,EAC/B,CACD,IACEQ,EAAcZ,IACfA,EAAQQ,OAAS,IAChBM,EAASd,EAASe,GAEnB,MAAM,IAAIL,UAAWC,EAAQ,gFAAiFX,IAI/G,GAFAA,EAAUgB,EAAgBhB,IAEpBiB,EAAUhB,GACf,MAAM,IAAIS,UAAWC,EAAQ,SAAUV,IAExC,IAAMiB,EAAwBjB,EAASkB,QACtC,MAAM,IAAIT,UAAWC,EAAQ,+GAAgHV,EAASkB,SAKvJ,GAHAhB,EAAO,CACNiB,MAASC,EAASC,IAAK,UAEnBf,UAA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,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 40de85b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 392b3b7eb97b7397bb4a40c405f04129df3b1b15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:03:39 +0000 Subject: [PATCH 20/45] 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 | 66 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5587 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C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", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a4d0103 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.0-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,I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C/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f492141..2eeb934 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.2", - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-copy": "^0.2.2", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.2", - "@stdlib/array-base-join": "^0.1.1", - "@stdlib/array-base-setter": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex-like": "^0.2.2", - "@stdlib/assert-is-empty-collection": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-object": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.3.0", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-binary": "^0.1.0", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.0", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.0", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.0", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.4.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-ndims": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/strided-base-nullary": "^0.3.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.4.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^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..629fb21 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 6cd015b49600cfbaa03eb4e7d8ae3038d6a7ba96 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:31:25 +0000 Subject: [PATCH 21/45] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4abc9e4..cd7dbde 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.0-esm/index.mjs'; ``` #### Random( prng, idtypes, odtypes, policies\[, options] ) @@ -230,7 +230,7 @@ import uniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-uniform@e import dtypes from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs'; import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.0-esm/index.mjs'; // Create a new PRNG instance... var idt = dtypes( 'real_and_generic' ); From c00c5262cdf8ee9370c366b7f4d60916f29ca003 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 08:31:26 +0000 Subject: [PATCH 22/45] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd7dbde..d208b29 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@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-tools-binary/tags). For example, + ```javascript import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.0-esm/index.mjs'; ``` @@ -230,7 +235,7 @@ import uniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-uniform@e import dtypes from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs'; import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.0-esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; // Create a new PRNG instance... var idt = dtypes( 'real_and_generic' ); From e80052b6112a19f1ae65913a7a678f3a6102d069 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:28:50 +0000 Subject: [PATCH 23/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 9836e93..e04b893 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 187852466ebe05d7ac60295e5d628c1633d251aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:22:59 +0000 Subject: [PATCH 24/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a4d0103..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.0-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.2-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.2-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.2-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACXM,EAASV,EAAIW,GAEd,MAAM,IAAIL,UAAWC,EAAQ,oFAAqFZ,IAEnHA,EAASM,GAAMW,EAAgBZ,EAC/B,CACD,IACEQ,EAAcZ,IACfA,EAAQQ,OAAS,IAChB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EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 629fb21..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c108eabed3f7e4fee6f67ba4f0bd1eb9493aa48c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:23:28 +0000 Subject: [PATCH 25/45] 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 | 76 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5590 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmod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UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a49ff07 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.3-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACXM,EAASV,EAAIW,GAEd,MAAM,IAAIL,UAAWC,EAAQ,oFAAqFZ,IAEnHA,EAASM,GAAMW,EAAgBZ,EAC/B,CACD,IACEQ,EAAcZ,IACfA,EAAQQ,OAAS,IAChBM,EAASd,EAASe,GAEnB,MAAM,IAAIL,UAAWC,EAAQ,gFAAiFX,IAI/G,GAFAA,EAAUgB,EAAgBhB,IAEpBiB,EAAUhB,GACf,MAAM,IAAIS,UAAWC,EAAQ,SAAUV,IAExC,IAAMiB,EAAwBjB,EAASkB,QACtC,MAAM,IAAIT,UAAWC,EAAQ,+GAAgHV,EAASkB,SAKvJ,GAHAhB,EAAO,CACNiB,MAASC,EAASC,IAAK,UAEnBf,UA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D,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e04b893..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/random-base-uniform": "^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..33ddfff --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 0f05c9b1866e23c7c58772c9ac3ee9c49a350674 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:47:01 +0000 Subject: [PATCH 26/45] Update README.md for ESM bundle v0.1.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1071a8c..501b675 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.1-esm/index.mjs'; ``` #### Random( prng, idtypes, odtypes, policies\[, options] ) @@ -230,7 +230,7 @@ import uniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-uniform@e import dtypes from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs'; import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.1-esm/index.mjs'; // Create a new PRNG instance... var idt = dtypes( 'real_and_generic' ); From 3409abff77396165fd41199499e46ee32c052c62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:47:02 +0000 Subject: [PATCH 27/45] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 501b675..f8a4466 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@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-tools-binary/tags). For example, + ```javascript import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.1-esm/index.mjs'; ``` @@ -230,7 +235,7 @@ import uniform from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-uniform@e import dtypes from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@esm/index.mjs'; import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; -import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@v0.1.1-esm/index.mjs'; +import Random from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-tools-binary@esm/index.mjs'; // Create a new PRNG instance... var idt = dtypes( 'real_and_generic' ); From dc0de9dee932ae10d5708bc8840975f40db4b8dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 03:41:58 +0000 Subject: [PATCH 28/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 78fcaef..ca5a245 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 582b416a837bd5cfeffa2248b2899685e728c33b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 05:09:00 +0000 Subject: [PATCH 29/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a49ff07..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.3-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,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IN,EACAsD,EACAC,EACAnD,EACAoD,EACAnC,EACApD,EAEJ,IAAM4D,EAAevB,GACpB,MAAM,IAAIhC,UAAWC,EAAQ,gFAAiF+B,IAE/G,GAAKmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 33ddfff..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2a1c98b2ed1206b0f7120ff17a766b45bc9479e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Mar 2026 05:09:41 +0000 Subject: [PATCH 30/45] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 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 | 76 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5591 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a991e5e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-09T02:52:16.598Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBR,EAAYQ,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBR,EAAYQ,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAAQ,SAEnBR,EAAYQ,EAAS,UAAW,IACpCF,EAAK,SAAWE,EAAQ,UAElB,MArBC,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE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6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACX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AChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ca5a245..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 77091439166b83da2fa9c667ac26a59f1ed4d505 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:44:03 +0000 Subject: [PATCH 31/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 78fcaef..ca5a245 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 199410b23a2be7c8e8da515405e57b29955d7610 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 04:13:22 +0000 Subject: [PATCH 32/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2aabb14..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EA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KmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a76c1e8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 659af4c049d6ff07bc2ca47292a2bb34eb192443 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 04:14:01 +0000 Subject: [PATCH 33/45] 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 | 76 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 112 - benchmark/benchmark.generate.js | 106 - benchmark/benchmark.js | 58 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5602 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 b0641d2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-10T03:32:01.141Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 5f6c4af..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':assign:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index c99b528..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':generate:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 00441ad..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBR,EAAYQ,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBR,EAAYQ,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAAQ,SAEnBR,EAAYQ,EAAS,UAAW,IACpCF,EAAK,SAAWE,EAAQ,UAElB,MArBC,IAAI,UAAWJ,EAAQ,qEA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AU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA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GAAKmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ca5a245..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 8a61c54cb3ca215e6d5adfd2f1d2f2107e623ada Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 19 Apr 2026 07:12:20 +0000 Subject: [PATCH 34/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 78fcaef..ca5a245 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 6d4ad43e383fad8b20fbf3b072a8b012c2870994 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 19 Apr 2026 07:18:17 +0000 Subject: [PATCH 35/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2aabb14..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,E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AAQ,gFAAiF+B,IAE/G,GAAKmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a76c1e8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 42b5e2f4dca9578a1d62e17ca0bed184d9a591cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 19 Apr 2026 07:18:47 +0000 Subject: [PATCH 36/45] 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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 110 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 113 - benchmark/benchmark.generate.js | 107 - benchmark/benchmark.js | 59 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 47 files changed, 4880 insertions(+), 5638 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 4ac2fd4..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:assign:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index 11731e8..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:generate:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 750816d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation', pkg ), function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBR,EAAYQ,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBR,EAAYQ,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAAQ,SAEnBR,EAAYQ,EAAS,UAAW,IACpCF,EAAK,SAAWE,EAAQ,UAElB,MArBC,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,CAsBh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M,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,IACXM,EAASV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AM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ca5a245..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 19530ad90bda605db252074c4777368fab6fbd03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 03:46:32 +0000 Subject: [PATCH 37/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 78fcaef..ca5a245 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 33c6de1264af4fc0fa315c329d6125aedb0485d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 04:01:31 +0000 Subject: [PATCH 38/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2aabb14..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,EAAGA,EAAIN,EAAQS,OAAQH,IAAM,CAEtC,GADAD,EAAKL,EAASM,IAEZO,EAAcR,IACfA,EAAGI,OAAS,I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,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a76c1e8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 245c977fa184fdca1625f1c0e31a5f9a38ffee42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 04:02:09 +0000 Subject: [PATCH 39/45] 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 | 110 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 113 - benchmark/benchmark.generate.js | 107 - benchmark/benchmark.js | 59 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5657 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 d730451..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-21T03:37:48.974Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 4ac2fd4..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:assign:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index 11731e8..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:generate:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 750816d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation', pkg ), function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 5d04b85..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAEjBR,EAAYQ,EAAS,MAAO,IAChCF,EAAK,KAAOE,EAAQ,MAEhBR,EAAYQ,EAAS,SAAU,IACnCF,EAAK,QAAUE,EAAQ,SAEnBR,EAAYQ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GA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGT5C,EAAU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAMd,GACVM,EAAI,E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ApD,EAEJ,IAAM4D,EAAevB,GACpB,MAAM,IAAIhC,UAAWC,EAAQ,gFAAiF+B,IAE/G,GAAKmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ca5a245..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From a0e6dd9dea0b2a00591c35771657cb032bbc3806 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:24:41 +0000 Subject: [PATCH 40/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 02f652f..15dc42d 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From 12908d0055640461e6318d4e3e58e70ec8da8425 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:34:32 +0000 Subject: [PATCH 41/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2aabb14..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAExC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAGxC,IADAA,EAAUc,EAAM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ACAoD,EACAnC,EACApD,EAEJ,IAAM4D,EAAevB,GACpB,MAAM,IAAIhC,UAAWC,EAAQ,gFAAiF+B,IAE/G,GAAKmD,EAAYnD,GAChB,MAAM,IAAIoD,MAAOnF,EAAO,WAKzB,GAHAiF,EAAKG,EAAUrD,GACfF,EAAM2B,EAAUzB,GAChBiD,EAAMzB,EAAUxB,IACVS,EAAU7C,KAAKsB,SAAUsB,EAAYyC,IAC1C,MAAM,IAAIjF,UAAWC,EAAQ,kGAAmGf,EAAU,GAAKwD,EAAM9C,KAAKsB,SAAU,QAAU+D,IAG/K,IADAvD,EAAS,CAAEF,EAAQC,GACb9B,EAAI,EAAGA,EAAI+B,EAAO5B,OAAQH,IAAM,CAyBrC,GAxBAoD,EAAIrB,EAAQ/B,GAGPyD,EAAUL,GAGdA,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,GACtBuB,EAAeN,IAEzBiC,EADqB,IAAjBjC,EAAEO,WACA,YAEA,aAGPP,EAAIiB,EAAiBjB,EAAGiC,EAAKE,EAAIpD,IACtByB,EAAeR,IAE1BiC,EAAMxB,EAAUT,GAChBA,EAAIkB,EAAWlB,EAAGmC,IAIlBnC,EAAIiB,EAAiBjB,EADrBiC,EAAM,UACuBE,EAAIpD,IAE5BW,EAAU7C,KAAKqB,SAAUtB,GAAK6C,EAAYwC,IAC/C,MAAM,IAAIhF,UAAWC,EAAQ,kGAAmGf,EAAUS,GAAK+C,EAAM9C,KAAKqB,SAAUtB,GAAK,QAAUqF,IAEpLtD,EAAQ/B,GAAMoD,CACd,CAKD,OAHArB,EAAOgC,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a76c1e8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 446eeed461709ea3617be6525d53943610029e81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jul 2026 03:35:01 +0000 Subject: [PATCH 42/45] 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 | 110 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 113 - benchmark/benchmark.generate.js | 107 - benchmark/benchmark.js | 59 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5657 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 457f397..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-07-02T03:22:02.151Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 4ac2fd4..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:assign:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index 11731e8..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:generate:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 750816d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation', pkg ), function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b889ce9..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){try{return r||t((r={exports:{}}).exports,r),r.exports}catch(e){throw r=0,e}}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAWF,EAAQ,gFAAiF,QAASF,EAAMK,EAAQ,MAAO,EAAGC,EAAQ,KAAM,CAAE,GAI7JR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQE,EAAQ,OAE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AAU,CAAE,EAAGvB,EAAM,KAAK,SAAU,MAAO,EAAGyD,CAAI,CAAE,EAGrL,IADAhC,EAAS,CAAEoB,EAAQC,CAAO,EACpBjB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGT5C,EAAU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GACjB,MAAM,IAAIY,U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js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 15dc42d..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -}); From 22eb24f084952d7540607cd0ef3279b5f93f51c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:19:50 +0000 Subject: [PATCH 43/45] Transform error messages --- lib/main.js | 14 +++++++------- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0b0db1b..445085b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -62,7 +62,7 @@ var defaults = require( '@stdlib/ndarray-defaults' ); var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var validate = require( './validate.js' ); @@ -299,10 +299,10 @@ function Random( prng, idtypes, odtypes, policies, options ) { return new Random( prng, idtypes, odtypes, policies, options ); } if ( !isFunction( prng ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) ); + throw new TypeError( format( 'null3c', prng ) ); } if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) ); + throw new TypeError( format( 'null2y', idtypes ) ); } idtypes = copy( idtypes ); for ( i = 0; i < idtypes.length; i++ ) { @@ -326,7 +326,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { odtypes = dtypes2strings( odtypes ); if ( !isObject( policies ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) ); + throw new TypeError( format( 'null43', policies ) ); } if ( !isOutputDataTypePolicy( policies.output ) ) { throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); @@ -336,7 +336,7 @@ function Random( prng, idtypes, odtypes, policies, options ) { }; if ( arguments.length > 4 ) { if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; @@ -414,7 +414,7 @@ setReadOnly( Random.prototype, 'generate', function generate( shape, param1, par var i; if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( 'null5o', shape ) ); } opts = {}; if ( arguments.length > 3 ) { @@ -557,7 +557,7 @@ setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); } if ( isReadOnly( out ) ) { - throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' ); + throw new Error( format('null1g') ); } sh = getShape( out ); ord = getOrder( out ); diff --git a/lib/validate.js b/lib/validate.js index 6ed34d2..27724b9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var contains = require( '@stdlib/array-base-assert-contains' ); var join = require( '@stdlib/array-base-join' ); var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -58,12 +58,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, dtypes, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'dtype' ) ) { opts.dtype = resolveStr( options.dtype ); if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), options.dtype ) ); + return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); } } // Pass-through options... diff --git a/package.json b/package.json index 02f652f..15dc42d 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@stdlib/ndarray-order": "^0.2.3", "@stdlib/ndarray-shape": "^0.2.3", "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" From c2be3af5d3e0d20379a15b8cddd57e894de02916 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:42:19 +0000 Subject: [PATCH 44/45] Remove files --- index.d.ts | 326 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5173 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 ee75e9b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,326 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// eslint-doctest-alias: Random - -// TypeScript Version: 4.1 - -/// - -import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { PRNG } from '@stdlib/types/random'; - -/** -* Interface defining constructor options. -*/ -interface ConstructorOptions { - /** - * Default memory layout. - */ - order?: Order; -} - -/** -* Interface defining options. -*/ -interface Options { - /** - * Output ndarray data type. - * - * ## Notes - * - * - Setting this option overrides the output data type policy. - */ - dtype?: DataType; - - /** - * Memory layout. - * - * ## Notes - * - * - Setting this option overrides the default memory layout. - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed ndarray dimensions. - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis. - */ - submode?: ArrayLike; - - /** - * Boolean indicating whether an ndarray should be read-only. - */ - readonly?: boolean; -} - -/** -* Interface defining class policies. -*/ -interface Policies { - /** - * Output data type policy. - */ - output: OutputPolicy; -} - -/** -* Interface for generating pseudorandom values drawn from a binary PRNG. -*/ -interface BinaryPRNG extends PRNG { - /** - * Returns a pseudorandom value. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @returns pseudorandom value - */ - ( param1: T, param2: U ): V; -} - -/** -* Class for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -*/ -declare class RandomArray { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - constructor( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ); - - /** - * Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - * - * @param shape - output shape - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param options - function options - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - generate( shape: Shape, param1: T | typedndarray, param2: U | typedndarray, options?: Options ): typedndarray; - - /** - * Fills an ndarray with pseudorandom values drawn from a binary PRNG. - * - * @param param1 - first PRNG parameter - * @param param2 - second PRNG parameter - * @param out - output ndarray - * @returns output ndarray - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var ndzeros = require( '@stdlib/ndarray-zeros' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var out = ndzeros( [ 2, 2 ] ); - * var v = rand.assign( 0.0, 1.0, out ); - * // returns - * - * var bool = ( v === out ); - * // returns true - */ - assign( param1: T | typedndarray, param2: U | typedndarray, out: typedndarray ): typedndarray; -} - -/** -* Interface defining a constructor which is both "newable" and "callable". -*/ -interface RandomArrayConstructor { - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - new( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; - - /** - * Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. - * - * @param prng - binary pseudorandom value generator - * @param idtypes - list containing a list of supported input data types for each PRNG parameter - * @param odtypes - list of supported output data types - * @param policies - dispatch policies - * @param options - function options - * @returns instance - * - * @example - * var dtypes = require( '@stdlib/ndarray-dtypes' ); - * var uniform = require( '@stdlib/random-base-uniform' ); - * - * var idt = dtypes( 'real_and_generic' ); - * var odt = dtypes( 'real_floating_point_and_generic' ); - * - * var policies = { - * 'output': 'real_floating_point_and_generic' - * }; - * var options = { - * 'order': 'row-major' - * }; - * - * var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); - * - * var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); - * // returns - */ - ( prng: BinaryPRNG, idtypes: [ ArrayLike, ArrayLike ], odtypes: ArrayLike, policies: Policies, options?: ConstructorOptions ): RandomArray; -} - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @param prng - binary pseudorandom value generator -* @param idtypes - list containing a list of supported input data types for each PRNG parameter -* @param odtypes - list of supported output data types -* @param policies - dispatch policies -* @param options - function options -* @returns instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -declare var ctor: RandomArrayConstructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2aabb14..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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,EAAQC,EAAMC,EAASC,EAASC,GAErC,IAAIJ,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAEtD,IAAMO,EAAYX,GAC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 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b28341758263285174e0f7c5573cd33bb9f88e03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 20 Aug 2026 03:42:48 +0000 Subject: [PATCH 45/45] 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 | 110 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- SECURITY.md | 5 - benchmark/benchmark.assign.js | 113 - benchmark/benchmark.generate.js | 107 - benchmark/benchmark.js | 59 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 131 - docs/types/test.ts | 405 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 79 - lib/main.js | 609 --- lib/validate.js | 88 - package.json | 99 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 35 - test/test.validate.js | 199 - 48 files changed, 4880 insertions(+), 5658 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.assign.js delete mode 100644 benchmark/benchmark.generate.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 328dc9f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-20T03:11:33.519Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 94083bc..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/tools/binary) 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 1bbeb9f..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/tools/binary) 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 fb85afa..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: '17 17 * * 5' - - # 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 + + ```
@@ -301,7 +292,7 @@ console.log( ndarray2array( x ) ); ## 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]. @@ -364,11 +355,11 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-tools-binary/main/LICENSE -[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies +[@stdlib/ndarray/policies]: https://github.com/stdlib-js/ndarray-policies/tree/esm -[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/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.assign.js b/benchmark/benchmark.assign.js deleted file mode 100644 index 4ac2fd4..0000000 --- a/benchmark/benchmark.assign.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var out; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - out = zeros( [ len ], { - 'dtype': 'float64' - }); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.assign( 0.0, 1.0, out ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:assign:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.generate.js b/benchmark/benchmark.generate.js deleted file mode 100644 index 11731e8..0000000 --- a/benchmark/benchmark.generate.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var policies; - var random; - var dt; - - dt = dtypes( 'real_floating_point' ); - policies = { - 'output': 'real_floating_point', - 'casting': 'none' - }; - random = new Random( uniform, [ dt, dt ], dt, policies ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - o = random.generate( [ len ], 0.0, 1.0 ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( isnan( o.get( 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 f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:generate:len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 750816d..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var uniform = require( '@stdlib/random-base-uniform' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var Random = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation', pkg ), function benchmark( b ) { - var policies; - var dtypes; - var v; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - policies = { - 'output': 'real_floating_point' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new Random( uniform, [ dtypes, dtypes ], dtypes, policies ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index eaee00f..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/tools/binary" -%% click B href "https://github.com/stdlib-js/random-tools-binary/tree/main" -%% click C href "https://github.com/stdlib-js/random-tools-binary/tree/production" -%% click D href "https://github.com/stdlib-js/random-tools-binary/tree/esm" -%% click E href "https://github.com/stdlib-js/random-tools-binary/tree/deno" -%% click F href "https://github.com/stdlib-js/random-tools-binary/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/tools/binary -[production-url]: https://github.com/stdlib-js/random-tools-binary/tree/production -[deno-url]: https://github.com/stdlib-js/random-tools-binary/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-tools-binary/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-tools-binary/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-tools-binary/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-tools-binary/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-tools-binary/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 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b889ce9..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var C=function(t,r){return function(){try{return r||t((r={exports:{}}).exports,r),r.exports}catch(e){throw r=0,e}}};var R=C(function(xr,N){"use strict";var X=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-has-own-property"),Y=require("@stdlib/array-base-assert-contains"),Z=require("@stdlib/array-base-join"),$=require("@stdlib/ndarray-base-dtype-resolve-str"),A=require("@stdlib/string-format");function rr(t,r,e){return X(e)?p(e,"dtype")&&(t.dtype=$(e.dtype),!Y(r,t.dtype))?new TypeError(A('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"dtype",Z(r,'", "'),e.dtype)):(p(e,"order")&&(t.order=e.order),p(e,"mode")&&(t.mode=e.mode),p(e,"submode")&&(t.submode=e.submode),p(e,"readonly")&&(t.readonly=e.readonly),null):new TypeError(A("invalid argument. Options argument must be an object. Value: `%s`.",e))}N.exports=rr});var W=C(function(Fr,U){"use strict";var z=require("@stdlib/utils-define-nonenumerable-read-only-property"),er=require("@stdlib/assert-is-nonnegative-integer-array").primitives,ar=require("@stdlib/assert-is-empty-collection"),D=require("@stdlib/assert-is-ndarray-like"),H=require("@stdlib/assert-is-number").isPrimitive,tr=require("@stdlib/assert-is-function"),J=require("@stdlib/assert-is-complex-like"),ir=require("@stdlib/assert-is-plain-object"),nr=require("@stdlib/assert-is-object"),S=require("@stdlib/assert-is-collection"),B=require("@stdlib/ndarray-base-assert-is-data-type"),ur=require("@stdlib/ndarray-base-assert-is-equal-data-type"),or=require("@stdlib/ndarray-base-assert-is-output-data-type-policy"),vr=require("@stdlib/ndarray-base-assert-is-read-only"),lr=require("@stdlib/ndarray-base-assert-is-order"),sr=require("@stdlib/assert-has-own-property"),x=require("@stdlib/array-base-assert-contains"),dr=require("@stdlib/array-base-filled-by"),I=require("@stdlib/array-base-every-by"),F=require("@stdlib/array-base-join"),fr=require("@stdlib/array-base-copy"),gr=require("@stdlib/strided-base-nullary"),K=require("@stdlib/ndarray-base-binary"),M=require("@stdlib/ndarray-base-maybe-broadcast-array"),T=require("@stdlib/ndarray-base-broadcast-scalar"),j=require("@stdlib/ndarray-base-shape2strides"),G=require("@stdlib/ndarray-base-dtypes2strings"),E=require("@stdlib/ndarray-base-dtype-resolve-str"),yr=require("@stdlib/ndarray-base-binary-output-dtype"),mr=require("@stdlib/ndarray-base-numel"),b=require("@stdlib/ndarray-base-buffer"),cr=require("@stdlib/ndarray-shape"),k=require("@stdlib/ndarray-dtype"),Q=require("@stdlib/ndarray-order"),hr=require("@stdlib/ndarray-ndims"),V=require("@stdlib/ndarray-ctor"),qr=require("@stdlib/ndarray-defaults"),pr=require("@stdlib/array-base-assert-is-accessor-array"),wr=require("@stdlib/array-base-accessor-setter"),br=require("@stdlib/array-base-setter"),f=require("@stdlib/string-format"),Tr=R(),L=["First","Second","Third"];function Er(t){var r,e,a,n;for(r=[],n=0;n4){if(!ir(n))throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",n));if(sr(n,"order")&&(i.order=n.order,!lr(i.order)))throw new TypeError(f("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",i.order))}return this._prng=t,this._idtypes=r,this._odtypes=e,this._policies={output:a.output},this._opts=i,this}z(h.prototype,"generate",function(r,e,a,n){var i,s,u,v,o,l,g,w,O,_,d,y,c,q,m;if(!er(r)&&!ar(r))throw new TypeError(f("invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.",r));if(u={},arguments.length>3&&(o=Tr(u,this._odtypes,n),o))throw o;for(i=Er([e,a]),m=0;m} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isEmptyCollection = require( '@stdlib/assert-is-empty-collection' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isComplexLike = require( '@stdlib/assert-is-complex-like' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' );\nvar isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar everyBy = require( '@stdlib/array-base-every-by' );\nvar join = require( '@stdlib/array-base-join' );\nvar copy = require( '@stdlib/array-base-copy' );\nvar nullaryStrided = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/ndarray-base-binary' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' );\nvar resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );\nvar binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar ndims = require( '@stdlib/ndarray-ndims' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar accessorSetter = require( '@stdlib/array-base-accessor-setter' );\nvar setter = require( '@stdlib/array-base-setter' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\nvar ORDINALS = [ 'First', 'Second', 'Third' ];\n\n\n// FUNCTIONS //\n\n/**\n* Performs an initial scan of a list of parameters.\n*\n* @private\n* @param {Array} params - list of parameters\n* @returns {Array} scan results\n*/\nfunction initialScan( params ) {\n\tvar out;\n\tvar p;\n\tvar o;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\to = {\n\t\t\t'scalar': true,\n\t\t\t'value': p,\n\t\t\t'dtype': '',\n\t\t\t'ndims': 0,\n\t\t\t'order': ''\n\t\t};\n\t\tif ( isNumber( p ) ) {\n\t\t\to.dtype = 'float64';\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\to.dtype = 'complex64';\n\t\t\t} else {\n\t\t\t\to.dtype = 'complex128';\n\t\t\t}\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\to.scalar = false;\n\t\t\to.dtype = resolveStr( getDType( p ) );\n\t\t\to.ndims = ndims( p );\n\t\t\to.order = getOrder( p );\n\t\t} else {\n\t\t\to.dtype = 'generic';\n\t\t}\n\t\tout.push( o );\n\t}\n\treturn out;\n}\n\n/**\n* Checks whether all parameters are scalar compatible.\n*\n* ## Notes\n*\n* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nmodule.exports = Random;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @module @stdlib/random-tools-binary\n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* var dtypes = require( '@stdlib/ndarray-dtypes' );\n* var ndzeros = require( '@stdlib/ndarray-zeros' );\n* var uniform = require( '@stdlib/random-base-uniform' );\n* var Random = require( '@stdlib/random-tools-binary' );\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EACzDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAa,QAAS,wCAAyC,EAC/DC,EAAS,QAAS,uBAAwB,EA+B9C,SAASC,GAAUC,EAAMC,EAAQC,EAAU,CAC1C,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,OAAQ,IACjCF,EAAK,MAAQH,EAAYK,EAAQ,KAAM,EAClC,CAACP,EAAUM,EAAQD,EAAK,KAAM,GAC3B,IAAI,UAAW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AAI,EACpB+B,EAAM5C,EAAUa,CAAI,EACf,CAAC7B,EAAU,KAAK,SAAUW,EAAYiD,CAAI,CAAE,EAChD,MAAM,IAAI,UAAWpC,EAAQ,kGAAmGE,EAAU,CAAE,EAAGvB,EAAM,KAAK,SAAU,MAAO,EAAGyD,CAAI,CAAE,EAGrL,IADAhC,EAAS,CAAEoB,EAAQC,CAAO,EACpBjB,EAAI,EAAGA,EAAIJ,EAAO,OAAQI,IAAM,CAyBrC,GAxBAF,EAAIF,EAAQI,CAAE,EAGT5C,EAAU0C,CAAE,GAEhB6B,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BjD,EAAewC,CAAE,GACvBA,EAAE,aAAe,EACrB6B,EAAM,YAENA,EAAM,aAGP7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAC1BpD,EAAe2C,CAAE,GAE5B6B,EAAM3C,EAAUc,CAAE,EAClBA,EAAIvB,EAAWuB,EAAG+B,CAAG,IAGrBF,EAAM,UACN7B,EAAItB,EAAiBsB,EAAG6B,EAAKE,EAAItB,CAAI,GAEjC,CAACvC,EAAU,KAAK,SAAUgC,CAAE,EAAGrB,EAAYgD,CAAI,CAAE,EACrD,MAAM,IAAI,UAAWnC,EAAQ,kGAAmGE,EAAUM,CAAE,EAAG7B,EAAM,KAAK,SAAU6B,CAAE,EAAG,MAAO,EAAG2B,CAAI,CAAE,EAE1L/B,EAAQI,CAAE,EAAIF,CACf,CAEA,OAAAF,EAAO,KAAMC,CAAI,EACjBvB,EAAQsB,EAAQ,KAAK,KAAM,EAEpBC,CACR,CAAC,EAKD9C,EAAO,QAAUyD,ICvhBjB,IAAIsB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "contains", "join", "resolveStr", "format", "validate", "opts", "dtypes", "options", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isNonNegativeIntegerArray", "isEmptyCollection", "isndarrayLike", "isNumber", "isFunction", "isComplexLike", "isPlainObject", "isObject", "isCollection", "isDataType", "isEqualDataType", "isOutputDataTypePolicy", "isReadOnly", "isOrder", "hasOwnProp", "contains", "filledBy", "everyBy", "join", "copy", "nullaryStrided", "binary", "broadcast", "broadcastScalar", "shape2strides", "dtypes2strings", "resolveStr", "binaryOutputDataType", "numel", "buffer", "getShape", "getDType", "getOrder", "ndims", "ndarray", "defaults", "isAccessorArray", "accessorSetter", "setter", "format", "validate", "ORDINALS", "initialScan", "params", "out", "p", "o", "i", "isScalarCompatible", "count", "convertToScalars", "resolveOrder", "broadcastParameters", "shape", "ord", "Random", "prng", "idtypes", "odtypes", "policies", "options", "opts", "dt", "param1", "param2", "buf", "err", "len", "FLG", "set", "st", "p1", "p2", "wrapper", "pdt", "odt", "sh", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ef8b35..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,131 +0,0 @@ - -{{alias}}( prng, idtypes, odtypes, policies[, options] ) - Returns an interface for creating ndarrays filled with pseudorandom values - drawn from a binary PRNG. - - Parameters - ---------- - prng: Function - Binary pseudorandom value generator. - - idtypes: Array> - List containing a list of supported input data types for each PRNG - parameter. - - odtypes: Array - List of supported output data types. - - policies: Object - Interface policies. Must have the following properties: - - - output: output data type policy. - - options: Object (optional) - Function options. - - options.order: string (optional) - Default memory layout. - - Returns - ------- - out: Object - Instance having methods for generating pseudorandom values. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var out = new {{alias}}( r, [ dts, dts ], dts, p ); - - -{{alias}}.prototype.generate( shape, param1, param2[, options] ) - Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - shape: Array - Output shape. - - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the specified output shape. - - options: Object (optional) - Function options. - - options.dtype: string|DataType (optional) - Output data type. Setting this option overrides the output data type - policy. - - options.order: string (optional) - Output memory layout. Setting this option overrides the default memory - layout order. - - options.mode: string (optional) - Specifies how to handle indices which exceed ndarray dimensions. - - options.submode: string (optional) - Specifies how to handle subscripts which exceed ndarray dimensions on a - per dimension basis. - - options.readonly: string (optional) - Boolean indicating whether an ndarray should be read-only. - - Returns - ------- - out: ndarray - Output ndarray. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var y = f.generate( [ 2, 2 ], 0.0, 1.0 ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - - -{{alias}}.prototype.assign( param1, param2, out ) - Fills an ndarray with pseudorandom values drawn from a binary PRNG. - - Parameters - ---------- - param1: ndarray|any - First PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - param2: ndarray|any - Second PRNG parameter. If an ndarray, must be broadcast compatible with - the output ndarray. - - out: ndarray - Output ndarray. - - Returns - ------- - out: ndarray - Output array. - - Examples - -------- - > var dts = [ 'float64', 'float32', 'generic' ]; - > var p = { 'output': 'real_floating_point_and_generic' }; - > var r = {{alias:@stdlib/random/base/uniform}}; - > var f = new {{alias}}( r, [ dts, dts ], dts, p ); - > var out = {{alias:@stdlib/ndarray/zeros}}( [ 2, 2 ] ); - > var y = f.assign( 0.0, 1.0, out ); - > {{alias:@stdlib/ndarray/to-array}}( y ) - [...] - > var bool = ( out === y ) - true - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index ea33c7d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,405 +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. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ - -/// - -import { DataType, OutputPolicy } from '@stdlib/types/ndarray'; -import uniform = require( '@stdlib/random-base-uniform' ); -import zeros = require( '@stdlib/ndarray-zeros' ); -import Random = require( './index' ); - - -// TESTS // - -// The function returns an instance for generating arrays of pseudorandom values... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - new Random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray - - const random = Random; - random( uniform, [ dt, dt ], dt, policies ); // $ExpectType RandomArray - random( uniform, [ dt, dt ], dt, policies, {} ); // $ExpectType RandomArray -} - -// The compiler throws an error if the function is provided a first argument which is not a PRNG function... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( '5', [ dt, dt ], dt, policies ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - new Random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - new Random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError - - const random = Random; - random( '5', [ dt, dt ], dt, policies ); // $ExpectError - random( 5, [ dt, dt ], dt, policies ); // $ExpectError - random( true, [ dt, dt ], dt, policies ); // $ExpectError - random( false, [ dt, dt ], dt, policies ); // $ExpectError - random( null, [ dt, dt ], dt, policies ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies ); // $ExpectError - random( {}, [ dt, dt ], dt, policies ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies ); // $ExpectError - - random( '5', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 5, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( true, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( false, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( null, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( void 0, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( 'abc', [ dt, dt ], dt, policies, {} ); // $ExpectError - random( {}, [ dt, dt ], dt, policies, {} ); // $ExpectError - random( ( x: number ): number => x, [ dt, dt ], dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a list containing lists of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, '5', dt, policies ); // $ExpectError - new Random( uniform, 5, dt, policies ); // $ExpectError - new Random( uniform, true, dt, policies ); // $ExpectError - new Random( uniform, false, dt, policies ); // $ExpectError - new Random( uniform, null, dt, policies ); // $ExpectError - new Random( uniform, void 0, dt, policies ); // $ExpectError - new Random( uniform, 'abc', dt, policies ); // $ExpectError - new Random( uniform, {}, dt, policies ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - new Random( uniform, '5', dt, policies, {} ); // $ExpectError - new Random( uniform, 5, dt, policies, {} ); // $ExpectError - new Random( uniform, true, dt, policies, {} ); // $ExpectError - new Random( uniform, false, dt, policies, {} ); // $ExpectError - new Random( uniform, null, dt, policies, {} ); // $ExpectError - new Random( uniform, void 0, dt, policies, {} ); // $ExpectError - new Random( uniform, 'abc', dt, policies, {} ); // $ExpectError - new Random( uniform, {}, dt, policies, {} ); // $ExpectError - new Random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, '5', dt, policies ); // $ExpectError - random( uniform, 5, dt, policies ); // $ExpectError - random( uniform, true, dt, policies ); // $ExpectError - random( uniform, false, dt, policies ); // $ExpectError - random( uniform, null, dt, policies ); // $ExpectError - random( uniform, void 0, dt, policies ); // $ExpectError - random( uniform, 'abc', dt, policies ); // $ExpectError - random( uniform, {}, dt, policies ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies ); // $ExpectError - - random( uniform, '5', dt, policies, {} ); // $ExpectError - random( uniform, 5, dt, policies, {} ); // $ExpectError - random( uniform, true, dt, policies, {} ); // $ExpectError - random( uniform, false, dt, policies, {} ); // $ExpectError - random( uniform, null, dt, policies, {} ); // $ExpectError - random( uniform, void 0, dt, policies, {} ); // $ExpectError - random( uniform, 'abc', dt, policies, {} ); // $ExpectError - random( uniform, {}, dt, policies, {} ); // $ExpectError - random( uniform, ( x: number ): number => x, dt, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a list of data types... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - new Random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], '5', policies ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies ); // $ExpectError - random( uniform, [ dt, dt ], true, policies ); // $ExpectError - random( uniform, [ dt, dt ], false, policies ); // $ExpectError - random( uniform, [ dt, dt ], null, policies ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies ); // $ExpectError - - random( uniform, [ dt, dt ], '5', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 5, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], true, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], false, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], null, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], void 0, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], 'abc', policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], {}, policies, {} ); // $ExpectError - random( uniform, [ dt, dt ], ( x: number ): number => x, policies, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... -{ - const dt: Array = [ 'float64', 'float32' ]; - - new Random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - new Random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError - - const random = Random; - random( uniform, [ dt, dt ], dt, '5' ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5 ); // $ExpectError - random( uniform, [ dt, dt ], dt, true ); // $ExpectError - random( uniform, [ dt, dt ], dt, false ); // $ExpectError - random( uniform, [ dt, dt ], dt, null ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0 ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc' ); // $ExpectError - random( uniform, [ dt, dt ], dt, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x ); // $ExpectError - - random( uniform, [ dt, dt ], dt, '5', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 5, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, true, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, false, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, null, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, void 0, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, 'abc', {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, {}, {} ); // $ExpectError - random( uniform, [ dt, dt ], dt, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - new Random(); // $ExpectError - new Random( uniform ); // $ExpectError - new Random( uniform, [ dt, dt ] ); // $ExpectError - new Random( uniform, [ dt, dt ], dt ); // $ExpectError - new Random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError - - const random = Random; - random(); // $ExpectError - random( uniform ); // $ExpectError - random( uniform, [ dt, dt ] ); // $ExpectError - random( uniform, [ dt, dt ], dt ); // $ExpectError - random( uniform, [ dt, dt ], dt, policies, {}, {} ); // $ExpectError -} - -// The function returns an instance having a `generate` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r1.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.generate( [ 2, 2 ], 0.0, 1.0 ); // $ExpectType typedndarray - r2.generate( [ 2, 2 ], 0.0, 1.0, {} ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `generate` method is provided a first argument which is not a valid shape... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( '5', 0.0, 1.0 ); // $ExpectError - r1.generate( 5, 0.0, 1.0 ); // $ExpectError - r1.generate( true, 0.0, 1.0 ); // $ExpectError - r1.generate( false, 0.0, 1.0 ); // $ExpectError - r1.generate( null, 0.0, 1.0 ); // $ExpectError - r1.generate( void 0, 0.0, 1.0 ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0 ); // $ExpectError - r1.generate( {}, 0.0, 1.0 ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0 ); // $ExpectError - - r1.generate( '5', 0.0, 1.0, {} ); // $ExpectError - r1.generate( 5, 0.0, 1.0, {} ); // $ExpectError - r1.generate( true, 0.0, 1.0, {} ); // $ExpectError - r1.generate( false, 0.0, 1.0, {} ); // $ExpectError - r1.generate( null, 0.0, 1.0, {} ); // $ExpectError - r1.generate( void 0, 0.0, 1.0, {} ); // $ExpectError - r1.generate( [ '5' ], 0.0, 1.0, {} ); // $ExpectError - r1.generate( {}, 0.0, 1.0, {} ); // $ExpectError - r1.generate( ( x: number ): number => x, 0.0, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided a fourth argument which is not an object... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, '5' ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, true ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, false ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, null ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, [] ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an invalid `dtype` option... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': '5' } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': 5 } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': true } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': false } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': null } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': [] } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': {} } ); // $ExpectError - r1.generate( [ 2,2 ], 0.0, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `generate` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.generate(); // $ExpectError - r1.generate( [ 2, 2 ] ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0 ); // $ExpectError - r1.generate( [ 2, 2 ], 0.0, 1.0, {}, {} ); // $ExpectError -} - -// The function returns an instance having an `assign` method which returns an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, x ); // $ExpectType typedndarray - - const random = Random; - const r2 = random( uniform, [ dt, dt ], dt, policies ); - r2.assign( 0.0, 1.0, x ); // $ExpectType typedndarray -} - -// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign( 0.0, 1.0, '5' ); // $ExpectError - r1.assign( 0.0, 1.0, 5 ); // $ExpectError - r1.assign( 0.0, 1.0, true ); // $ExpectError - r1.assign( 0.0, 1.0, false ); // $ExpectError - r1.assign( 0.0, 1.0, null ); // $ExpectError - r1.assign( 0.0, 1.0, void 0 ); // $ExpectError - r1.assign( 0.0, 1.0, {} ); // $ExpectError - r1.assign( 0.0, 1.0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... -{ - const dt: Array = [ 'float64', 'float32' ]; - const policies = { - 'output': 'same' as OutputPolicy - }; - const x = zeros( [ 5, 5 ], { - 'dtype': 'float64' - }); - - const r1 = new Random( uniform, [ dt, dt ], dt, policies ); - r1.assign(); // $ExpectError - r1.assign( 0.0 ); // $ExpectError - r1.assign( 0.0, 1.0 ); // $ExpectError - r1.assign( 0.0, 1.0, x, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index b692f97..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var uniform = require( '@stdlib/random-base-uniform' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var Random = require( './../lib' ); - -// Create a new PRNG instance... -var idt = dtypes( 'real_and_generic' ); -var odt = dtypes( 'real_floating_point_and_generic' ); -var policies = { - 'output': 'real_floating_point_and_generic' -}; -var random = new Random( uniform, [ idt, idt ], odt, policies ); - -// Generate a 3x3 matrix of pseudorandom numbers: -var x = random.generate( [ 3, 3 ], 0.0, 1.0 ); -console.log( ndarray2array( x ) ); - -// Generate another matrix with a specified data type: -x = random.generate( [ 3, 3 ], 0.0, 1.0, { - 'dtype': 'float32' -}); -console.log( ndarray2array( x ) ); - -// Define arrays of distribution parameters: -var param1 = new ndarray( 'generic', [ 1.0, 10.0, 100.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); -var param2 = new ndarray( 'generic', [ 2.0, 20.0, 200.0 ], [ 3, 1 ], [ 1, 1 ], 0, 'row-major' ); - -// Broadcast the parameters to generate another 3x3 matrix of pseudorandom numbers: -x = random.generate( [ 3, 3 ], param1, param2 ); -console.log( ndarray2array( x ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5e47761..ee75e9b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { DataType, Order, Mode, Shape, OutputPolicy, typedndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2aabb14 --- /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{primitives as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-empty-collection@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex-like@v0.2.4-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-equal-data-type@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-output-data-type-policy@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.3-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.3-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-every-by@v0.2.3-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-join@v0.1.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy@v0.2.3-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-nullary@v0.3.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary@v0.1.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.5-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-scalar@v0.2.4-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.3-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2strings@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-str@v0.3.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-binary-output-dtype@v0.1.1-esm/index.mjs";import S from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.3-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.3-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.3-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ndims@v0.2.3-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.3.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.4.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.3-esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-setter@v0.2.3-esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-setter@v0.2.3-esm/index.mjs";import I from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var J=["First","Second","Third"];function K(e,t,r,s,n){var d,p,j;if(!(this instanceof K))return arguments.length<5?new K(e,t,r,s):new K(e,t,r,s,n);if(!i(e))throw new TypeError(I("null3c",e));if(!m(t))throw new TypeError(I("null2y",t));for(t=b(t),j=0;j4){if(!o(n))throw new TypeError(I("null2V",n));if(y(n,"order")&&(d.order=n.order,!v(d.order)))throw new TypeError(I("invalid option. `%s` option must be a valid memory layout. Option: `%s`.","order",d.order))}return this._prng=e,this._idtypes=t,this._odtypes=r,this._policies={output:s.output},this._opts=d,this}e(K.prototype,"generate",(function(e,i,a,m){var l,h,j,v,f,b,V,L,B,K,M,N,P,Q;if(!t(e)&&!r(e))throw new TypeError(I("null5o",e));if(j={},arguments.length>3&&(f=function(e,t,r){return o(r)?y(r,"dtype")&&(e.dtype=k(r.dtype),!u(t,e.dtype))?new TypeError(I("null4S","dtype",g(t,'", "'),r.dtype)):(y(r,"order")&&(e.order=r.order),y(r,"mode")&&(e.mode=r.mode),y(r,"submode")&&(e.submode=r.submode),y(r,"readonly")&&(e.readonly=r.readonly),null):new TypeError(I("null2V",r))}(j,this._odtypes,m),f))throw f;for(l=function(e){var t,r,i,o;for(t=[],o=0;o} params - list of parameter objects\n* @returns {boolean} boolean indicating whether all parameters are scalar compatible\n*/\nfunction isScalarCompatible( params ) {\n\tvar count;\n\tvar p;\n\tvar i;\n\n\tcount = 0;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar || p.ndims === 0 ) {\n\t\t\tcount += 1;\n\t\t}\n\t}\n\treturn ( count === params.length );\n}\n\n/**\n* Converts a list of parameters to scalar values.\n*\n* ## Notes\n*\n* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction convertToScalars( params ) {\n\tvar p;\n\tvar i;\n\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar === false ) {\n\t\t\tp.scalar = true;\n\t\t\tp.value = p.value.get();\n\t\t\tp.ndims = 0;\n\t\t\tp.order = '';\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Resolves a common memory layout from a list of parameter objects.\n*\n* @private\n* @param {Array} params - list of parameter objects\n* @returns {string} memory layout\n*/\nfunction resolveOrder( params ) {\n\tvar p;\n\tvar i;\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other...\n\t\tif ( p.scalar === false ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn p.order;\n}\n\n/**\n* Broadcasts parameter values to an ndarray having a specified shape.\n*\n* ## Notes\n*\n* - The function **mutates** the input array.\n*\n* @private\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Array} params - list of parameter objects\n* @returns {Array} updated list\n*/\nfunction broadcastParameters( shape, params ) {\n\tvar ord;\n\tvar p;\n\tvar i;\n\n\tord = resolveOrder( params );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\t\tif ( p.scalar ) {\n\t\t\tp.scalar = false;\n\t\t\tp.value = broadcastScalar( p.value, p.dtype, shape, ord );\n\t\t\tp.order = ord;\n\t\t} else {\n\t\t\tp.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t}\n\t\tp.ndims = shape.length;\n\t}\n\treturn params;\n}\n\n\n// MAIN //\n\n/**\n* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.\n*\n* @constructor\n* @param {Function} prng - binary pseudorandom value generator\n* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter\n* @param {ArrayLikeObject} odtypes - list of supported output data types\n* @param {Object} policies - policies\n* @param {string} policies.output - output data type policy\n* @param {Object} [options] - function options\n* @param {string} [options.order] - default memory layout\n* @throws {TypeError} first argument must be a function\n* @throws {TypeError} second argument must be an array containing arrays of supported data types\n* @throws {TypeError} third argument must be an array of supported data types\n* @throws {TypeError} fourth argument must be an object having supported policies\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Random} instance\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nfunction Random( prng, idtypes, odtypes, policies, options ) {\n\tvar opts;\n\tvar dt;\n\tvar i;\n\tif ( !( this instanceof Random ) ) {\n\t\tif ( arguments.length < 5 ) {\n\t\t\treturn new Random( prng, idtypes, odtypes, policies );\n\t\t}\n\t\treturn new Random( prng, idtypes, odtypes, policies, options );\n\t}\n\tif ( !isFunction( prng ) ) {\n\t\tthrow new TypeError( format( 'null3c', prng ) );\n\t}\n\tif ( !isCollection( idtypes ) ) {\n\t\tthrow new TypeError( format( 'null2y', idtypes ) );\n\t}\n\tidtypes = copy( idtypes );\n\tfor ( i = 0; i < idtypes.length; i++ ) {\n\t\tdt = idtypes[ i ];\n\t\tif (\n\t\t\t!isCollection( dt ) ||\n\t\t\tdt.length < 1 ||\n\t\t\t!everyBy( dt, isDataType )\n\t\t) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );\n\t\t}\n\t\tidtypes[ i ] = dtypes2strings( dt );\n\t}\n\tif (\n\t\t!isCollection( odtypes ) ||\n\t\todtypes.length < 1 ||\n\t\t!everyBy( odtypes, isDataType )\n\t) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );\n\t}\n\todtypes = dtypes2strings( odtypes );\n\n\tif ( !isObject( policies ) ) {\n\t\tthrow new TypeError( format( 'null43', policies ) );\n\t}\n\tif ( !isOutputDataTypePolicy( policies.output ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );\n\t}\n\topts = {\n\t\t'order': defaults.get( 'order' )\n\t};\n\tif ( arguments.length > 4 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\topts.order = options.order;\n\t\t\tif ( !isOrder( opts.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) );\n\t\t\t}\n\t\t}\n\t}\n\tthis._prng = prng;\n\tthis._idtypes = idtypes;\n\tthis._odtypes = odtypes;\n\tthis._policies = {\n\t\t'output': policies.output\n\t};\n\tthis._opts = opts;\n\treturn this;\n}\n\n/**\n* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG.\n*\n* @name generate\n* @memberof Random.prototype\n* @type {Function}\n* @param {NonNegativeIntegerArray} shape - output shape\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {Options} [options] - function options\n* @param {*} [options.dtype] - output ndarray data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - 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 PRNG parameters\n* @throws {TypeError} PRNG 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* import dtypes from '@stdlib/ndarray-dtypes';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 );\n* // returns \n*/\nsetReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) {\n\tvar params;\n\tvar prng;\n\tvar opts;\n\tvar buf;\n\tvar err;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\tvar out;\n\tvar set;\n\tvar dt;\n\tvar st;\n\tvar p1;\n\tvar p2;\n\tvar i;\n\n\tif ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) {\n\t\tthrow new TypeError( format( 'null5o', shape ) );\n\t}\n\topts = {};\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, this._odtypes, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tparams = initialScan( [ param1, param2 ] );\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tdt = params[ i ].dtype;\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '\", \"' ), dt ) );\n\t\t}\n\t}\n\tFLG = isScalarCompatible( params );\n\tif ( FLG ) {\n\t\tparams = convertToScalars( params );\n\t} else {\n\t\tparams = broadcastParameters( shape, params );\n\t}\n\tp1 = params[ 0 ];\n\tp2 = params[ 1 ];\n\tprng = this._prng;\n\tdt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len\n\tif ( opts.order ) {\n\t\tord = opts.order;\n\t} else if ( FLG ) {\n\t\tord = this._opts.order;\n\t} else {\n\t\t// If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another:\n\t\tord = p1.order;\n\t}\n\t// Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero...\n\tlen = numel( shape );\n\tif ( len === 0 ) {\n\t\t// Check for a zero-dimensional shape...\n\t\tif ( shape.length === 0 ) {\n\t\t\t// If the output array is a zero-dimensional ndarray, we generate a single random variate...\n\t\t\tbuf = buffer( dt, 1 );\n\t\t\tif ( isAccessorArray( buf ) ) {\n\t\t\t\tset = accessorSetter( dt );\n\t\t\t} else {\n\t\t\t\tset = setter( dt );\n\t\t\t}\n\t\t\tset( buf, 0, prng( p1.value, p2.value ) );\n\t\t\tst = [ 0 ];\n\t\t} else {\n\t\t\t// If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray...\n\t\t\tbuf = buffer( dt, len );\n\t\t\tst = shape2strides( shape, ord );\n\t\t}\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray...\n\tif ( FLG ) {\n\t\tif ( isEqualDataType( dt, 'generic' ) ) {\n\t\t\tbuf = filledBy( len, wrapper );\n\t\t} else {\n\t\t\tbuf = buffer( dt, len );\n\t\t\tnullaryStrided( [ buf ], [ len ], [ 1 ], wrapper );\n\t\t}\n\t\tst = shape2strides( shape, ord );\n\t\treturn new ndarray( dt, buf, shape, st, 0, ord, opts );\n\t}\n\t// We've been provided ndarrays, so we need to perform element-wise iteration...\n\n\t// Allocate a data buffer:\n\tbuf = buffer( dt, len );\n\n\t// Initialize the output array:\n\tst = shape2strides( shape, ord );\n\tout = new ndarray( dt, buf, shape, st, 0, ord, opts );\n\n\t// Fill the output array with pseudorandom values:\n\tbinary( [ p1.value, p2.value, out ], prng );\n\n\treturn out;\n\n\t/**\n\t* Applies parameters to a pseudorandom number generator function.\n\t*\n\t* @private\n\t* @returns {(number|ComplexLike)} pseudorandom number\n\t*/\n\tfunction wrapper() {\n\t\treturn prng( p1.value, p2.value );\n\t}\n});\n\n/**\n* Fills an ndarray with pseudorandom values drawn from a binary PRNG.\n*\n* @name assign\n* @memberof Random.prototype\n* @type {Function}\n* @param {(ndarrayLike|*)} param1 - first PRNG parameter\n* @param {(ndarrayLike|*)} param2 - second PRNG parameter\n* @param {ndarrayLike} out - output ndarray\n* @throws {TypeError} third argument must be an ndarray\n* @throws {TypeError} must provide valid PRNG parameters\n* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {ndarray} output ndarray\n*\n* @example\n* import dtypes from '@stdlib/ndarray-dtypes';\n* import ndzeros from '@stdlib/ndarray-zeros';\n* import uniform from '@stdlib/random-base-uniform';\n*\n* var idt = dtypes( 'real_and_generic' );\n* var odt = dtypes( 'real_floating_point_and_generic' );\n*\n* var policies = {\n* 'output': 'real_floating_point_and_generic'\n* };\n* var options = {\n* 'order': 'row-major'\n* };\n*\n* var rand = new Random( uniform, [ idt, idt ], odt, policies, options );\n*\n* var out = ndzeros( [ 2, 2 ] );\n* var v = rand.assign( 0.0, 1.0, out );\n* // returns \n*\n* var bool = ( v === out );\n* // returns true\n*/\nsetReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) {\n\tvar params;\n\tvar pdt;\n\tvar odt;\n\tvar ord;\n\tvar sh;\n\tvar p;\n\tvar i;\n\n\tif ( !isndarrayLike( out ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );\n\t}\n\tif ( isReadOnly( out ) ) {\n\t\tthrow new Error( format('null1g') );\n\t}\n\tsh = getShape( out );\n\tord = getOrder( out );\n\todt = getDType( out );\n\tif ( !contains( this._odtypes, resolveStr( odt ) ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '\", \"' ), odt ) );\n\t}\n\tparams = [ param1, param2 ];\n\tfor ( i = 0; i < params.length; i++ ) {\n\t\tp = params[ i ];\n\n\t\t// Check whether we've been provided a scalar PRNG parameter...\n\t\tif ( isNumber( p ) ) {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'float64';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isComplexLike( p ) ) {\n\t\t\tif ( p.byteLength === 8 ) {\n\t\t\t\tpdt = 'complex64';\n\t\t\t} else {\n\t\t\t\tpdt = 'complex128';\n\t\t\t}\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t} else if ( isndarrayLike( p ) ) {\n\t\t\t// Broadcast the PRNG parameter to the desired shape:\n\t\t\tpdt = getDType( p );\n\t\t\tp = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility\n\t\t} else {\n\t\t\t// Wrap the scalar in a broadcasted ndarray:\n\t\t\tpdt = 'generic';\n\t\t\tp = broadcastScalar( p, pdt, sh, ord );\n\t\t}\n\t\tif ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. %s argument must have one of the following data types: \"%s\". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '\", \"' ), pdt ) );\n\t\t}\n\t\tparams[ i ] = p;\n\t}\n\t// Fill the output array with pseudorandom values:\n\tparams.push( out );\n\tbinary( params, this._prng );\n\n\treturn out;\n});\n\n\n// EXPORTS //\n\nexport default Random;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport contains from '@stdlib/array-base-assert-contains';\nimport join from '@stdlib/array-base-join';\nimport resolveStr from '@stdlib/ndarray-base-dtype-resolve-str';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Array} dtypes - list of supported output data types\n* @param {Options} options - function options\n* @param {*} [options.dtype] - array data type\n* @param {string} [options.order] - memory layout (either row-major or column-major)\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var dtypes = [ 'float64', 'float32', 'generic' ];\n*\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, dtypes, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, dtypes, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\topts.dtype = resolveStr( options.dtype );\n\t\tif ( !contains( dtypes, opts.dtype ) ) {\n\t\t\treturn new TypeError( format( 'null4S', 'dtype', join( dtypes, '\", \"' ), options.dtype ) );\n\t\t}\n\t}\n\t// Pass-through options...\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["ORDINALS","Random","prng","idtypes","odtypes","policies","options","opts","dt","i","this","arguments","length","isFunction","TypeError","format","isCollection","copy","everyBy","isDataType","dtypes2strings","isObject","isOutputDataTypePolicy","output","order","defaults","get","isPlainObject","hasOwnProp","isOrder","_prng","_idtypes","_odtypes","_policies","_opts","setReadOnly","prototype","shape","param1","param2","params","buf","err","len","ord","FLG","out","st","p1","p2","isNonNegativeIntegerArray","isEmptyCollection","dtypes","dtype","resolveStr","contains","join","mode","submode","readonly","validate","p","o","scalar","value","ndims","isNumber","isComplexLike","byteLength","isndarrayLike","getDType","getOrder","push","initialScan","count","isScalarCompatible","convertToScalars","resolveOrder","broadcastScalar","broadcast","broadcastParameters","binaryOutputDataType","numel","buffer","isAccessorArray","accessorSetter","setter","shape2strides","ndarray","isEqualDataType","filledBy","wrapper","nullaryStrided","binary","pdt","odt","sh","isReadOnly","Error","getShape"],"mappings":";;0+HAsEA,IAAIA,EAAW,CAAE,QAAS,SAAU,SA4NpC,SAASC,EAAQC,EAAMC,EAASC,EAASC,EAAUC,GAClD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,GACvB,OAAKU,UAAUC,OAA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C,KAAM1B,GACb+C,EAAQrD,EAAQ9B,KAAKoB,OAEdgB,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 9ecec8f..0000000 --- a/lib/index.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @module @stdlib/random-tools-binary -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* var Random = require( '@stdlib/random-tools-binary' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 445085b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,609 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isEmptyCollection = require( '@stdlib/assert-is-empty-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var isComplexLike = require( '@stdlib/assert-is-complex-like' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isEqualDataType = require( '@stdlib/ndarray-base-assert-is-equal-data-type' ); -var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var filledBy = require( '@stdlib/array-base-filled-by' ); -var everyBy = require( '@stdlib/array-base-every-by' ); -var join = require( '@stdlib/array-base-join' ); -var copy = require( '@stdlib/array-base-copy' ); -var nullaryStrided = require( '@stdlib/strided-base-nullary' ); -var binary = require( '@stdlib/ndarray-base-binary' ); -var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -var broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var dtypes2strings = require( '@stdlib/ndarray-base-dtypes2strings' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var ndims = require( '@stdlib/ndarray-ndims' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var defaults = require( '@stdlib/ndarray-defaults' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var accessorSetter = require( '@stdlib/array-base-accessor-setter' ); -var setter = require( '@stdlib/array-base-setter' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -var ORDINALS = [ 'First', 'Second', 'Third' ]; - - -// FUNCTIONS // - -/** -* Performs an initial scan of a list of parameters. -* -* @private -* @param {Array} params - list of parameters -* @returns {Array} scan results -*/ -function initialScan( params ) { - var out; - var p; - var o; - var i; - - out = []; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - o = { - 'scalar': true, - 'value': p, - 'dtype': '', - 'ndims': 0, - 'order': '' - }; - if ( isNumber( p ) ) { - o.dtype = 'float64'; - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - o.dtype = 'complex64'; - } else { - o.dtype = 'complex128'; - } - } else if ( isndarrayLike( p ) ) { - o.scalar = false; - o.dtype = resolveStr( getDType( p ) ); - o.ndims = ndims( p ); - o.order = getOrder( p ); - } else { - o.dtype = 'generic'; - } - out.push( o ); - } - return out; -} - -/** -* Checks whether all parameters are scalar compatible. -* -* ## Notes -* -* - A parameter is scalar compatible if, and only if, the parameter value is either a zero-dimensional ndarray or already a scalar value. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {boolean} boolean indicating whether all parameters are scalar compatible -*/ -function isScalarCompatible( params ) { - var count; - var p; - var i; - - count = 0; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar || p.ndims === 0 ) { - count += 1; - } - } - return ( count === params.length ); -} - -/** -* Converts a list of parameters to scalar values. -* -* ## Notes -* -* - The function **mutates** the input array by updating parameter objects which do not already correspond to scalar parameter values. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function convertToScalars( params ) { - var p; - var i; - - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar === false ) { - p.scalar = true; - p.value = p.value.get(); - p.ndims = 0; - p.order = ''; - } - } - return params; -} - -/** -* Resolves a common memory layout from a list of parameter objects. -* -* @private -* @param {Array} params - list of parameter objects -* @returns {string} memory layout -*/ -function resolveOrder( params ) { - var p; - var i; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // For a binary parameter function, we simply return the layout of the first parameter having a layout, as there is no clear rationale for picking the layout of one parameter over another and picking the first one we find is as good a rationale as any other... - if ( p.scalar === false ) { - break; - } - } - return p.order; -} - -/** -* Broadcasts parameter values to an ndarray having a specified shape. -* -* ## Notes -* -* - The function **mutates** the input array. -* -* @private -* @param {NonNegativeIntegerArray} shape - array shape -* @param {Array} params - list of parameter objects -* @returns {Array} updated list -*/ -function broadcastParameters( shape, params ) { - var ord; - var p; - var i; - - ord = resolveOrder( params ); - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - if ( p.scalar ) { - p.scalar = false; - p.value = broadcastScalar( p.value, p.dtype, shape, ord ); - p.order = ord; - } else { - p.value = broadcast( p.value, shape ); // delegate to `broadcast` to ensure broadcast compatibility - } - p.ndims = shape.length; - } - return params; -} - - -// MAIN // - -/** -* Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG. -* -* @constructor -* @param {Function} prng - binary pseudorandom value generator -* @param {ArrayLikeObject} idtypes - list containing a list of supported input data types for each PRNG parameter -* @param {ArrayLikeObject} odtypes - list of supported output data types -* @param {Object} policies - policies -* @param {string} policies.output - output data type policy -* @param {Object} [options] - function options -* @param {string} [options.order] - default memory layout -* @throws {TypeError} first argument must be a function -* @throws {TypeError} second argument must be an array containing arrays of supported data types -* @throws {TypeError} third argument must be an array of supported data types -* @throws {TypeError} fourth argument must be an object having supported policies -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Random} instance -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -function Random( prng, idtypes, odtypes, policies, options ) { - var opts; - var dt; - var i; - if ( !( this instanceof Random ) ) { - if ( arguments.length < 5 ) { - return new Random( prng, idtypes, odtypes, policies ); - } - return new Random( prng, idtypes, odtypes, policies, options ); - } - if ( !isFunction( prng ) ) { - throw new TypeError( format( 'null3c', prng ) ); - } - if ( !isCollection( idtypes ) ) { - throw new TypeError( format( 'null2y', idtypes ) ); - } - idtypes = copy( idtypes ); - for ( i = 0; i < idtypes.length; i++ ) { - dt = idtypes[ i ]; - if ( - !isCollection( dt ) || - dt.length < 1 || - !everyBy( dt, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) ); - } - idtypes[ i ] = dtypes2strings( dt ); - } - if ( - !isCollection( odtypes ) || - odtypes.length < 1 || - !everyBy( odtypes, isDataType ) - ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) ); - } - odtypes = dtypes2strings( odtypes ); - - if ( !isObject( policies ) ) { - throw new TypeError( format( 'null43', policies ) ); - } - if ( !isOutputDataTypePolicy( policies.output ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) ); - } - opts = { - 'order': defaults.get( 'order' ) - }; - if ( arguments.length > 4 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a valid memory layout. Option: `%s`.', 'order', opts.order ) ); - } - } - } - this._prng = prng; - this._idtypes = idtypes; - this._odtypes = odtypes; - this._policies = { - 'output': policies.output - }; - this._opts = opts; - return this; -} - -/** -* Returns an ndarray filled with pseudorandom values drawn from a binary PRNG. -* -* @name generate -* @memberof Random.prototype -* @type {Function} -* @param {NonNegativeIntegerArray} shape - output shape -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {Options} [options] - function options -* @param {*} [options.dtype] - output ndarray data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed ndarray dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed ndarray dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an ndarray should be read-only -* @throws {TypeError} first argument must be a valid shape -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG 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 dtypes = require( '@stdlib/ndarray-dtypes' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var v = rand.generate( [ 2, 2 ], 0.0, 1.0 ); -* // returns -*/ -setReadOnly( Random.prototype, 'generate', function generate( shape, param1, param2, options ) { - var params; - var prng; - var opts; - var buf; - var err; - var len; - var ord; - var FLG; - var out; - var set; - var dt; - var st; - var p1; - var p2; - var i; - - if ( !isNonNegativeIntegerArray( shape ) && !isEmptyCollection( shape ) ) { - throw new TypeError( format( 'null5o', shape ) ); - } - opts = {}; - if ( arguments.length > 3 ) { - err = validate( opts, this._odtypes, options ); - if ( err ) { - throw err; - } - } - params = initialScan( [ param1, param2 ] ); - for ( i = 0; i < params.length; i++ ) { - dt = params[ i ].dtype; - if ( !contains( this._idtypes[ i ], resolveStr( dt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i+1 ], join( this._idtypes[ i ], '", "' ), dt ) ); - } - } - FLG = isScalarCompatible( params ); - if ( FLG ) { - params = convertToScalars( params ); - } else { - params = broadcastParameters( shape, params ); - } - p1 = params[ 0 ]; - p2 = params[ 1 ]; - prng = this._prng; - dt = opts.dtype || binaryOutputDataType( p1.dtype, p2.dtype, this._policies.output ); // eslint-disable-line max-len - if ( opts.order ) { - ord = opts.order; - } else if ( FLG ) { - ord = this._opts.order; - } else { - // If we don't have any explicit order info, use the order of the first parameter, as no clear rationale for choosing the order of one parameter over another: - ord = p1.order; - } - // Handles special cases involving (1) zero-dimensional output ndarrays and (2) shapes having at least one dimension of size zero... - len = numel( shape ); - if ( len === 0 ) { - // Check for a zero-dimensional shape... - if ( shape.length === 0 ) { - // If the output array is a zero-dimensional ndarray, we generate a single random variate... - buf = buffer( dt, 1 ); - if ( isAccessorArray( buf ) ) { - set = accessorSetter( dt ); - } else { - set = setter( dt ); - } - set( buf, 0, prng( p1.value, p2.value ) ); - st = [ 0 ]; - } else { - // If the output array has one or more dimensions of size zero, we avoid allocating any memory, and instead return an empty ndarray... - buf = buffer( dt, len ); - st = shape2strides( shape, ord ); - } - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // If provided scalar PRNG parameters, we can simply fill a linear buffer with pseudorandom values (as all pseudorandom values are drawn from the same PRNG) and then wrap as an ndarray... - if ( FLG ) { - if ( isEqualDataType( dt, 'generic' ) ) { - buf = filledBy( len, wrapper ); - } else { - buf = buffer( dt, len ); - nullaryStrided( [ buf ], [ len ], [ 1 ], wrapper ); - } - st = shape2strides( shape, ord ); - return new ndarray( dt, buf, shape, st, 0, ord, opts ); - } - // We've been provided ndarrays, so we need to perform element-wise iteration... - - // Allocate a data buffer: - buf = buffer( dt, len ); - - // Initialize the output array: - st = shape2strides( shape, ord ); - out = new ndarray( dt, buf, shape, st, 0, ord, opts ); - - // Fill the output array with pseudorandom values: - binary( [ p1.value, p2.value, out ], prng ); - - return out; - - /** - * Applies parameters to a pseudorandom number generator function. - * - * @private - * @returns {(number|ComplexLike)} pseudorandom number - */ - function wrapper() { - return prng( p1.value, p2.value ); - } -}); - -/** -* Fills an ndarray with pseudorandom values drawn from a binary PRNG. -* -* @name assign -* @memberof Random.prototype -* @type {Function} -* @param {(ndarrayLike|*)} param1 - first PRNG parameter -* @param {(ndarrayLike|*)} param2 - second PRNG parameter -* @param {ndarrayLike} out - output ndarray -* @throws {TypeError} third argument must be an ndarray -* @throws {TypeError} must provide valid PRNG parameters -* @throws {TypeError} PRNG parameters and the output ndarray must be broadcast compatible -* @throws {Error} cannot write to a read-only ndarray -* @returns {ndarray} output ndarray -* -* @example -* var dtypes = require( '@stdlib/ndarray-dtypes' ); -* var ndzeros = require( '@stdlib/ndarray-zeros' ); -* var uniform = require( '@stdlib/random-base-uniform' ); -* -* var idt = dtypes( 'real_and_generic' ); -* var odt = dtypes( 'real_floating_point_and_generic' ); -* -* var policies = { -* 'output': 'real_floating_point_and_generic' -* }; -* var options = { -* 'order': 'row-major' -* }; -* -* var rand = new Random( uniform, [ idt, idt ], odt, policies, options ); -* -* var out = ndzeros( [ 2, 2 ] ); -* var v = rand.assign( 0.0, 1.0, out ); -* // returns -* -* var bool = ( v === out ); -* // returns true -*/ -setReadOnly( Random.prototype, 'assign', function assign( param1, param2, out ) { - var params; - var pdt; - var odt; - var ord; - var sh; - var p; - var i; - - if ( !isndarrayLike( out ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); - } - if ( isReadOnly( out ) ) { - throw new Error( format('null1g') ); - } - sh = getShape( out ); - ord = getOrder( out ); - odt = getDType( out ); - if ( !contains( this._odtypes, resolveStr( odt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ 2 ], join( this._odtypes, '", "' ), odt ) ); - } - params = [ param1, param2 ]; - for ( i = 0; i < params.length; i++ ) { - p = params[ i ]; - - // Check whether we've been provided a scalar PRNG parameter... - if ( isNumber( p ) ) { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'float64'; - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isComplexLike( p ) ) { - if ( p.byteLength === 8 ) { - pdt = 'complex64'; - } else { - pdt = 'complex128'; - } - // Wrap the scalar in a broadcasted ndarray: - p = broadcastScalar( p, pdt, sh, ord ); - } else if ( isndarrayLike( p ) ) { - // Broadcast the PRNG parameter to the desired shape: - pdt = getDType( p ); - p = broadcast( p, sh ); // delegate to `broadcast` to ensure broadcast compatibility - } else { - // Wrap the scalar in a broadcasted ndarray: - pdt = 'generic'; - p = broadcastScalar( p, pdt, sh, ord ); - } - if ( !contains( this._idtypes[ i ], resolveStr( pdt ) ) ) { - throw new TypeError( format( 'invalid argument. %s argument must have one of the following data types: "%s". Data type: `%s`.', ORDINALS[ i ], join( this._idtypes[ i ], '", "' ), pdt ) ); - } - params[ i ] = p; - } - // Fill the output array with pseudorandom values: - params.push( out ); - binary( params, this._prng ); - - return out; -}); - - -// EXPORTS // - -module.exports = Random; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 27724b9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var contains = require( '@stdlib/array-base-assert-contains' ); -var join = require( '@stdlib/array-base-join' ); -var resolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Array} dtypes - list of supported output data types -* @param {Options} options - function options -* @param {*} [options.dtype] - array data type -* @param {string} [options.order] - memory layout (either row-major or column-major) -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {ArrayLikeObject} [options.submode] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var dtypes = [ 'float64', 'float32', 'generic' ]; -* -* var options = { -* 'dtype': 'float64' -* }; -* var err = validate( opts, dtypes, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, dtypes, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'dtype' ) ) { - opts.dtype = resolveStr( options.dtype ); - if ( !contains( dtypes, opts.dtype ) ) { - return new TypeError( format( 'null4S', 'dtype', join( dtypes, '", "' ), options.dtype ) ); - } - } - // Pass-through options... - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 15dc42d..12acbaf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "Constructor for creating ndarrays filled with pseudorandom values drawn from a binary PRNG.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-setter": "^0.2.3", - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.3", - "@stdlib/array-base-copy": "^0.2.3", - "@stdlib/array-base-every-by": "^0.2.3", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-base-join": "^0.1.2", - "@stdlib/array-base-setter": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-complex-like": "^0.2.4", - "@stdlib/assert-is-empty-collection": "^0.2.4", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.3", - "@stdlib/ndarray-base-assert-is-equal-data-type": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.3", - "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-binary": "^0.1.1", - "@stdlib/ndarray-base-binary-output-dtype": "^0.1.1", - "@stdlib/ndarray-base-broadcast-scalar": "^0.2.4", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-dtype-resolve-str": "^0.3.1", - "@stdlib/ndarray-base-dtypes2strings": "^0.1.1", - "@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-shape2strides": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-defaults": "^0.4.1", - "@stdlib/ndarray-dtype": "^0.2.3", - "@stdlib/ndarray-ndims": "^0.2.3", - "@stdlib/ndarray-order": "^0.2.3", - "@stdlib/ndarray-shape": "^0.2.3", - "@stdlib/strided-base-nullary": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/ndarray-dtypes": "^0.4.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/random-base-uniform": "^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..a76c1e8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d13b709..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var 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(); -}); - -// FIXME: add tests diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index d83a636..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,199 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// VARIABLES // - -var DTYPES = [ - 'float64', - 'float32', - 'generic' -]; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `dtype` option which is not a supported data type', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 'foo', - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, DTYPES, { - 'dtype': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports the `order` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'order': 'row-major' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `mode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `submode` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'submode': [ 'throw' ] - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports the `readonly` array creation option', function test( t ) { - var options; - var opts; - var err; - - options = { - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'dtype': 'float64', - 'order': 'row-major', - 'mode': 'throw', - 'submode': [ 'throw' ], - 'readonly': true - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, DTYPES, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -});