diff --git a/array/coverage.ndjson b/array/coverage.ndjson index ff2ce8bca..2ebf3ae59 100644 --- a/array/coverage.ndjson +++ b/array/coverage.ndjson @@ -2,3 +2,4 @@ [712,712,100,1,1,100,0,0,100,712,712,100,"de73ae19f43cbad40036d25b1d46620b3c5113a9","2023-08-25 16:40:46 -0700"] [712,712,100,1,1,100,0,0,100,712,712,100,"8482c0a4ed75ea8cc40ae22a1e1ee1a5de595269","2023-12-31 03:42:20 -0800"] [712,712,100,1,1,100,0,0,100,712,712,100,"cf1ec758b8476b43e90df835af6e545a41890cfd","2023-12-31 03:49:21 -0800"] +[721,721,100,1,1,100,0,0,100,721,721,100,"94a238318c73272acb232ac6066f596e07a8752d","2024-01-04 22:22:23 -0800"] diff --git a/array/defaults/coverage.ndjson b/array/defaults/coverage.ndjson new file mode 100644 index 000000000..57fe64ea1 --- /dev/null +++ b/array/defaults/coverage.ndjson @@ -0,0 +1 @@ +[161,161,100,5,6,83.3333,2,2,100,161,161,100,"94a238318c73272acb232ac6066f596e07a8752d","2024-01-04 22:22:23 -0800"] diff --git a/array/defaults/get.js.html b/array/defaults/get.js.html new file mode 100644 index 000000000..f9721183c --- /dev/null +++ b/array/defaults/get.js.html @@ -0,0 +1,271 @@ + + + + + + Code coverage report for array/defaults/lib/get.js + + + + + + + + + +
+
+

All files / array/defaults/lib get.js

+
+ +
+ 100% + Statements + 62/62 +
+ + +
+ 66.66% + Branches + 2/3 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 62/62 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +632x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +9x +9x +9x +9x +2x +2x +2x +2x +2x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+ 
+'use strict';
+ 
+// MODULES //
+ 
+var defaults = require( './main.js' );
+ 
+ 
+// VARIABLES //
+ 
+var DEFAULTS = defaults();
+var HASH = {
+	'dtypes.default': DEFAULTS.dtypes.default,
+	'dtypes.numeric': DEFAULTS.dtypes.numeric,
+	'dtypes.real': DEFAULTS.dtypes.real,
+	'dtypes.floating_point': DEFAULTS.dtypes.floating_point,
+	'dtypes.real_floating_point': DEFAULTS.dtypes.real_floating_point,
+	'dtypes.complex_floating_point': DEFAULTS.dtypes.complex_floating_point,
+	'dtypes.integer': DEFAULTS.dtypes.integer,
+	'dtypes.signed_integer': DEFAULTS.dtypes.signed_integer,
+	'dtypes.unsigned_integer': DEFAULTS.dtypes.unsigned_integer
+};
+ 
+ 
+// MAIN //
+ 
+/**
+* Returns a default array setting.
+*
+* @param {string} name - setting name
+* @returns {*} default setting or null
+*
+* @example
+* var v = get( 'dtypes.default' );
+* // returns <string>
+*/
+function get( name ) {
+	var v = HASH[ name ];
+	return ( v === void 0 ) ? null : v;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = get;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/array/defaults/index.html b/array/defaults/index.html new file mode 100644 index 000000000..0c207ee15 --- /dev/null +++ b/array/defaults/index.html @@ -0,0 +1,146 @@ + + + + + + Code coverage report for array/defaults/lib + + + + + + + + + +
+
+

All files array/defaults/lib

+
+ +
+ 100% + Statements + 161/161 +
+ + +
+ 83.33% + Branches + 5/6 +
+ + +
+ 100% + Functions + 2/2 +
+ + +
+ 100% + Lines + 161/161 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
get.js +
+
100%62/6266.66%2/3100%1/1100%62/62
index.js +
+
100%47/47100%1/1100%0/0100%47/47
main.js +
+
100%52/52100%2/2100%1/1100%52/52
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/array/defaults/index.js.html b/array/defaults/index.js.html new file mode 100644 index 000000000..a46e6eeaf --- /dev/null +++ b/array/defaults/index.js.html @@ -0,0 +1,226 @@ + + + + + + Code coverage report for array/defaults/lib/index.js + + + + + + + + + +
+
+

All files / array/defaults/lib index.js

+
+ +
+ 100% + Statements + 47/47 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 47/47 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +481x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+ 
+'use strict';
+ 
+/**
+* Return default array settings.
+*
+* @module @stdlib/array/defaults
+*
+* @example
+* var defaults = require( '@stdlib/array/defaults' );
+*
+* var o = defaults();
+* // returns {...}
+*/
+ 
+// MODULES //
+ 
+var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
+var main = require( './main.js' );
+var get = require( './get.js' );
+ 
+ 
+// MAIN //
+ 
+setReadOnly( main, 'get', get );
+ 
+ 
+// EXPORTS //
+ 
+module.exports = main;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/array/defaults/main.js.html b/array/defaults/main.js.html new file mode 100644 index 000000000..152bdeeb9 --- /dev/null +++ b/array/defaults/main.js.html @@ -0,0 +1,241 @@ + + + + + + Code coverage report for array/defaults/lib/main.js + + + + + + + + + +
+
+

All files / array/defaults/lib main.js

+
+ +
+ 100% + Statements + 52/52 +
+ + +
+ 100% + Branches + 2/2 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 52/52 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +533x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +4x +3x +3x +3x +3x +3x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+ 
+'use strict';
+ 
+// MAIN //
+ 
+/**
+* Returns default array settings.
+*
+* @returns {Object} defaults
+*
+* @example
+* var o = defaults();
+* // returns {...}
+*/
+function defaults() {
+	return {
+		// Data types:
+		'dtypes': {
+			'default': 'float64',
+			'numeric': 'float64',
+			'real': 'float64',
+			'floating_point': 'float64',
+			'real_floating_point': 'float64',
+			'complex_floating_point': 'complex128',
+			'integer': 'int32',
+			'signed_integer': 'int32',
+			'unsigned_integer': 'uint32'
+		}
+	};
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = defaults;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/array/dtypes/coverage.ndjson b/array/dtypes/coverage.ndjson index 04f216928..fcf69c8c1 100644 --- a/array/dtypes/coverage.ndjson +++ b/array/dtypes/coverage.ndjson @@ -1,2 +1,3 @@ [84,84,100,3,3,100,1,1,100,84,84,100] [94,94,100,7,7,100,1,1,100,94,94,100,"fca5a4950e85bac6e21ff1665924489c1bcb9643","2023-12-31 02:58:06 -0800"] +[114,114,100,13,13,100,1,1,100,114,114,100,"94a238318c73272acb232ac6066f596e07a8752d","2024-01-04 22:22:23 -0800"] diff --git a/array/dtypes/index.html b/array/dtypes/index.html index 3683f59ee..1801c9f42 100644 --- a/array/dtypes/index.html +++ b/array/dtypes/index.html @@ -3,15 +3,15 @@ - Code coverage report for All files + Code coverage report for array/dtypes/lib - - - + + + @@ -19,20 +19,20 @@
-

All files

+

All files array/dtypes/lib

100% Statements - 94/94 + 114/114
100% Branches - 7/7 + 13/13
@@ -46,7 +46,7 @@

All files

100% Lines - 94/94 + 114/114
@@ -99,13 +99,13 @@

All files

100% - 54/54 + 74/74 100% - 6/6 + 12/12 100% 1/1 100% - 54/54 + 74/74 @@ -116,16 +116,16 @@

All files

- + - - + + \ No newline at end of file diff --git a/array/dtypes/index.js.html b/array/dtypes/index.js.html index 753ccf212..e7399bf06 100644 --- a/array/dtypes/index.js.html +++ b/array/dtypes/index.js.html @@ -3,15 +3,15 @@ - Code coverage report for index.js + Code coverage report for array/dtypes/lib/index.js - - - + + + @@ -19,7 +19,7 @@
-

All files index.js

+

All files / array/dtypes/lib index.js

@@ -190,16 +190,16 @@

All files index.js

- + - - + + \ No newline at end of file diff --git a/array/dtypes/main.js.html b/array/dtypes/main.js.html index 906f554ec..0e280e94e 100644 --- a/array/dtypes/main.js.html +++ b/array/dtypes/main.js.html @@ -3,15 +3,15 @@ - Code coverage report for main.js + Code coverage report for array/dtypes/lib/main.js - - - + + + @@ -19,20 +19,20 @@
-

All files main.js

+

All files / array/dtypes/lib main.js

100% Statements - 54/54 + 74/74
100% Branches - 6/6 + 12/12
@@ -46,7 +46,7 @@

All files main.js

100% Lines - 54/54 + 74/74
@@ -117,7 +117,27 @@

All files main.js

52 53 54 -551x +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +751x 1x 1x 1x @@ -158,14 +178,34 @@

All files main.js

1x 1x 1x -11x -11x -11x 1x 1x -10x +1x +1x +1x +1x +24x +24x +24x +24x +24x +1x +1x +23x +23x +24x 11x 11x +10x +10x +11x +23x +24x +24x +8x +8x +23x +24x 1x 1x 1x @@ -193,9 +233,15 @@

All files main.js

  // MODULES //   +var replace = require( '@stdlib/string/base/replace' ); var DTYPES = require( './dtypes.json' );     +// VARIABLES // +  +var RE_SUFFIX = /_and_generic$/; +  +  // MAIN //   /** @@ -206,19 +252,33 @@

All files main.js

* * @example * var list = dtypes(); -* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ] +* // e.g., returns [ 'float32', 'float64', ... ] * * @example * var list = dtypes( 'floating_point' ); * // returns [...] */ function dtypes() { + var kind; var out; + var FLG; if ( arguments.length === 0 ) { return DTYPES.all.slice(); } - out = DTYPES[ arguments[ 0 ] ]; - return ( out ) ? out.slice() : []; + FLG = false; + kind = arguments[ 0 ]; + if ( RE_SUFFIX.test( kind ) ) { + kind = replace( kind, RE_SUFFIX, '' ); + if ( kind !== 'all' ) { + FLG = true; + } + } + out = DTYPES[ kind ]; + out = ( out ) ? out.slice() : []; + if ( FLG && out.length > 0 ) { + out.push( 'generic' ); + } + return out; }     @@ -232,16 +292,16 @@

All files main.js

- + - - + + \ No newline at end of file diff --git a/array/index.html b/array/index.html index 2b697d7a4..7da84d474 100644 --- a/array/index.html +++ b/array/index.html @@ -25,7 +25,7 @@

All files array/lib

100% Statements - 712/712 + 721/721
@@ -46,7 +46,7 @@

All files array/lib

100% Lines - 712/712 + 721/721
@@ -84,13 +84,13 @@

All files array/lib

100% - 712/712 + 721/721 100% 1/1 100% 0/0 100% - 712/712 + 721/721 @@ -101,7 +101,7 @@

All files array/lib

+ + + + + + \ No newline at end of file diff --git a/random/array/tools/nullary/index.js.html b/random/array/tools/nullary/index.js.html new file mode 100644 index 000000000..64940ee9d --- /dev/null +++ b/random/array/tools/nullary/index.js.html @@ -0,0 +1,223 @@ + + + + + + Code coverage report for random/array/tools/nullary/lib/index.js + + + + + + + + + +
+
+

All files / random/array/tools/nullary/lib index.js

+
+ +
+ 100% + Statements + 46/46 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 46/46 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +471x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR 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 arrays filled with pseudorandom values drawn from a nullary PRNG.
+*
+* @module @stdlib/random/array/tools/nullary
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+* var Random = require( '@stdlib/random/array/tools/nullary' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential.factory( 2.0 ), dtypes, defaultDType );
+*
+* var v = rand.generate( 10 );
+* // returns <Float64Array>
+*/
+ 
+// MODULES //
+ 
+var main = require( './main.js' );
+ 
+ 
+// EXPORTS //
+ 
+module.exports = main;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/nullary/main.js.html b/random/array/tools/nullary/main.js.html new file mode 100644 index 000000000..781a62182 --- /dev/null +++ b/random/array/tools/nullary/main.js.html @@ -0,0 +1,607 @@ + + + + + + Code coverage report for random/array/tools/nullary/lib/main.js + + + + + + + + + +
+
+

All files / random/array/tools/nullary/lib main.js

+
+ +
+ 72.41% + Statements + 126/174 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 72.41% + Lines + 126/174 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +1751x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
+var isFunction = require( '@stdlib/assert/is-function' );
+var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
+var isCollection = require( '@stdlib/assert/is-collection' );
+var contains = require( '@stdlib/array/base/assert/contains' );
+var filledBy = require( '@stdlib/array/base/filled-by' );
+var nullary = require( '@stdlib/strided/base/nullary' );
+var ctors = require( '@stdlib/array/ctors' );
+var format = require( '@stdlib/string/format' );
+var validate = require( './validate.js' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Constructor for creating arrays filled with pseudorandom values drawn from a nullary PRNG.
+*
+* @constructor
+* @param {Function} prng - nullary pseudorandom value generator
+* @param {StringArray} dtypes - list of supported output data types
+* @param {string} dtype - default output data type
+* @throws {TypeError} first argument must be a function
+* @throws {TypeError} second argument must be an array of strings
+* @throws {TypeError} third argument must be a supported data type
+* @returns {Random} instance
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential.factory( 2.0 ), dtypes, defaultDType );
+*
+* var v = rand.generate( 10 );
+* // returns <Float64Array>
+*/
+function Random( prng, dtypes, dtype ) {
+	if ( !( this instanceof Random ) ) {
+		return new Random( prng, dtypes, dtype );
+	}
+	if ( !isFunction( prng ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );
+	}
+	// TODO: tighten this up by actually validating that `dtypes` contains only recognized/supported dtype strings
+	if ( !isStringArray( dtypes ) ) {
+		throw new TypeError( format( 'invalid argument. Second argument must be an array of strings. Value: `%s`.', dtypes ) );
+	}
+	// Require that the default output array data type be a member of the list of supported output array data types...
+	if ( !contains( dtypes, dtype ) ) {
+		throw new TypeError( format( 'invalid argument. Third argument must be a supported data type. Value: `%s`.', dtype ) );
+	}
+	this._prng = prng;
+	this._dtypes = dtypes;
+	this._dtype = dtype;
+	return this;
+}
+ 
+/**
+* Returns an array filled with pseudorandom values drawn from a nullary PRNG.
+*
+* @name generate
+* @memberof Random.prototype
+* @type {Function}
+* @param {NonNegativeInteger} len - number of elements
+* @param {Options} [options] - function options
+* @param {string} [options.dtype] - array data type
+* @throws {TypeError} first argument must be a nonnegative integer
+* @throws {TypeError} options argument must be an object
+* @throws {TypeError} must provide valid options
+* @returns {Collection} output array
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential.factory( 2.0 ), dtypes, defaultDType );
+*
+* var v = rand.generate( 10 );
+* // returns <Float64Array>
+*/
+setReadOnly( Random.prototype, 'generate', function generate( len, options ) {
+	var ctor;
+	var opts;
+	var out;
+	var err;
+	var dt;
+	if ( !isNonNegativeInteger( len ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );
+	}
+	opts = {};
+	if ( arguments.length > 1 ) {
+		err = validate( opts, this._dtypes, options );
+		if ( err ) {
+			throw err;
+		}
+	}
+	dt = opts.dtype || this._dtype;
+	if ( dt === 'generic' ) {
+		return filledBy( len, this._prng );
+	}
+	ctor = ctors( dt );
+	out = new ctor( len );
+	nullary( [ out ], [ len ], [ 1 ], this._prng );
+	return out;
+});
+ 
+/**
+* Fills an array with pseudorandom values drawn from a nullary PRNG.
+*
+* @name assign
+* @memberof Random.prototype
+* @type {Function}
+* @param {Collection} out - output array
+* @throws {TypeError} first argument must be a collection
+* @returns {Collection} output array
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+* var zeros = require( '@stdlib/array/zeros' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential.factory( 2.0 ), dtypes, defaultDType );
+*
+* var out = zeros( 10, 'float64' );
+* // returns <Float64Array>
+*
+* var v = rand.assign( out );
+* // returns <Float64Array>
+*
+* var bool = ( v === out );
+* // returns true
+*/
+setReadOnly( Random.prototype, 'assign', function assign( out ) {
+	if ( !isCollection( out ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', out ) );
+	}
+	nullary( [ out ], [ out.length ], [ 1 ], this._prng );
+	return out;
+});
+ 
+ 
+// EXPORTS //
+ 
+module.exports = Random;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/nullary/validate.js.html b/random/array/tools/nullary/validate.js.html new file mode 100644 index 000000000..dd01c6d84 --- /dev/null +++ b/random/array/tools/nullary/validate.js.html @@ -0,0 +1,289 @@ + + + + + + Code coverage report for random/array/tools/nullary/lib/validate.js + + + + + + + + + +
+
+

All files / random/array/tools/nullary/lib validate.js

+
+ +
+ 82.35% + Statements + 56/68 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 82.35% + Lines + 56/68 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +691x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string/format' );
+ 
+ 
+// 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 {string} [options.dtype] - output array data type
+* @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( 'invalid argument. Options argument must be an object. Value: `%s`.', 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', dtypes.join( '", "' ), opts.dtype ) );
+		}
+	}
+	return null;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = validate;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary-factory/coverage.ndjson b/random/array/tools/unary-factory/coverage.ndjson new file mode 100644 index 000000000..f8310c66e --- /dev/null +++ b/random/array/tools/unary-factory/coverage.ndjson @@ -0,0 +1 @@ +[137,362,37.8453,2,2,100,0,1,0,137,362,37.8453,"94a238318c73272acb232ac6066f596e07a8752d","2024-01-04 22:22:23 -0800"] diff --git a/random/array/tools/unary-factory/index.html b/random/array/tools/unary-factory/index.html new file mode 100644 index 000000000..644d9ad1a --- /dev/null +++ b/random/array/tools/unary-factory/index.html @@ -0,0 +1,131 @@ + + + + + + Code coverage report for random/array/tools/unary-factory/lib + + + + + + + + + +
+
+

All files random/array/tools/unary-factory/lib

+
+ +
+ 37.84% + Statements + 137/362 +
+ + +
+ 100% + Branches + 2/2 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 37.84% + Lines + 137/362 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.js +
+
100%49/49100%1/1100%0/0100%49/49
main.js +
+
28.11%88/313100%1/10%0/128.11%88/313
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary-factory/index.js.html b/random/array/tools/unary-factory/index.js.html new file mode 100644 index 000000000..3ca8e2555 --- /dev/null +++ b/random/array/tools/unary-factory/index.js.html @@ -0,0 +1,232 @@ + + + + + + Code coverage report for random/array/tools/unary-factory/lib/index.js + + + + + + + + + +
+
+

All files / random/array/tools/unary-factory/lib index.js

+
+ +
+ 100% + Statements + 49/49 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 49/49 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +501x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+ 
+'use strict';
+ 
+/**
+* Create a factory function for generating pseudorandom values drawn from a unary PRNG.
+*
+* @module @stdlib/random/array/tools/unary-factory
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+* var unaryFactory = require( '@stdlib/random/array/tools/unary-factory' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+*
+* var factory = unaryFactory( exponential, dtypes, 'float64' );
+* // returns <Function>
+*
+* var random = factory();
+* // returns <Function>
+*
+* var x = random( 10, 0.2 );
+* // returns <Float64Array>
+*/
+ 
+// MODULES //
+ 
+var main = require( './main.js' );
+ 
+ 
+// EXPORTS //
+ 
+module.exports = main;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary-factory/main.js.html b/random/array/tools/unary-factory/main.js.html new file mode 100644 index 000000000..b3e5a2a8c --- /dev/null +++ b/random/array/tools/unary-factory/main.js.html @@ -0,0 +1,1024 @@ + + + + + + Code coverage report for random/array/tools/unary-factory/lib/main.js + + + + + + + + + +
+
+

All files / random/array/tools/unary-factory/lib main.js

+
+ +
+ 28.11% + Statements + 88/313 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 28.11% + Lines + 88/313 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +3141x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+ 
+'use strict';
+ 
+// MODULES //
+ 
+var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' );
+var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' );
+var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
+var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
+var isFunction = require( '@stdlib/assert/is-function' );
+var isMethodIn = require( '@stdlib/assert/is-method-in' );
+var isPlainObject = require( '@stdlib/assert/is-plain-object' );
+var hasOwnProp = require( '@stdlib/assert/has-own-property' );
+var contains = require( '@stdlib/array/base/assert/contains' ).factory;
+var constantFunction = require( '@stdlib/utils/constant-function' );
+var noop = require( '@stdlib/utils/noop' );
+var UnaryRandom = require( '@stdlib/random/array/tools/unary' );
+var NullaryRandom = require( '@stdlib/random/array/tools/nullary' );
+var format = require( '@stdlib/string/format' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Returns a factory function for generating pseudorandom values drawn from a unary PRNG.
+*
+* @param {Function} prng - unary pseudorandom value generator
+* @param {Function} prng.factory - method which returns a new unary pseudorandom value generator
+* @param {StringArray} dtypes - list of supported output array data types
+* @param {string} dtype - default output array data type
+* @throws {TypeError} first argument must be a function
+* @throws {TypeError} first argument must have a `factory` method
+* @throws {TypeError} second argument must be an array of strings
+* @throws {TypeError} third argument must be a supported output array data type
+* @returns {Function} function which returns a function for creating arrays
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+*
+* var factory = createFactory( exponential, dtypes, 'float64' );
+* // returns <Function>
+*
+* var random = factory();
+* // returns <Function>
+*
+* var x = random( 10, 0.2 );
+* // returns <Float64Array>
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+*
+* var factory = createFactory( exponential, dtypes, 'float64' );
+* // returns <Function>
+*
+* var random = factory();
+* // returns <Function>
+*
+* var x = random( 10, 0.2, {
+*     'dtype': 'float32'
+* });
+* // returns <Float32Array>
+*/
+function createFactory( prng, dtypes, dtype ) {
+	var isValidDataType;
+	if ( !isFunction( prng ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );
+	}
+	if ( !isMethodIn( prng, 'factory' ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must have a `%s` method.', 'factory' ) );
+	}
+	// TODO: tighten this up by actually validating that `dtypes` contains only recognized/supported dtype strings
+	if ( !isStringArray( dtypes ) ) {
+		throw new TypeError( format( 'invalid argument. Second argument must an array of strings. Value: `%s`.', dtypes ) );
+	}
+	// Require that the default output array data type be a member of the list of supported output array data types...
+	if ( !contains( dtypes, dtype ) ) {
+		throw new TypeError( format( 'invalid argument. Third argument must be a supported data type. Value: `%s`.', dtype ) );
+	}
+	isValidDataType = contains( dtypes );
+	return factory;
+
+	/**
+	* Returns a function for generating pseudorandom values drawn from a PRNG.
+	*
+	* @private
+	* @param {*} [param1] - PRNG parameter
+	* @param {Options} [options] - function options
+	* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers
+	* @param {*} [options.seed] - pseudorandom value generator seed
+	* @param {*} [options.state] - pseudorandom value generator state
+	* @param {boolean} [options.copy] - boolean indicating whether to copy a provided pseudorandom value generator state
+	* @param {string} [options.dtype] - default output array data type
+	* @throws {TypeError} options argument must be an object
+	* @throws {TypeError} must provide valid options
+	* @throws {Error} must provide a valid state
+	* @returns {Function} function for creating arrays
+	*/
+	function factory() {
+		var Random;
+		var random;
+		var param1;
+		var assign;
+		var nargs;
+		var base;
+		var opts;
+		var rand;
+		var dt;
+
+		nargs = arguments.length;
+		if ( nargs < 1 ) {                              // e.g., factory()
+			opts = {};
+			base = prng;
+			rand = rand1;
+		} else if ( nargs > 1 ) {                       // e.g., factory( param1, {} )
+			param1 = arguments[ 0 ];
+			opts = arguments[ 1 ];
+			base = prng.factory( param1, opts );
+			rand = rand2;
+		} else if ( isPlainObject( arguments[ 0 ] ) ) { // e.g., factory( {} )
+			opts = arguments[ 0 ];
+			base = prng.factory( opts );
+			rand = rand1;
+		} else {                                        // e.g., factory( param1 )
+			param1 = arguments[ 0 ];
+			opts = {};
+			base = prng.factory( param1 );
+			rand = rand2;
+		}
+		if ( hasOwnProp( opts, 'dtype' ) ) {
+			dt = opts.dtype;
+			if ( !isValidDataType( dt ) ) {
+				throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', dtypes.join( '", "' ), dt ) );
+			}
+		} else {
+			dt = dtype;
+		}
+		if ( rand === rand1 ) {
+			assign = assign1;
+			Random = UnaryRandom;
+		} else {
+			assign = assign2;
+			Random = NullaryRandom;
+		}
+		random = new Random( base, dtypes, dt );
+		if ( opts && opts.prng ) {
+			setReadOnly( rand, 'seed', null );
+			setReadOnly( rand, 'seedLength', null );
+			setReadWriteAccessor( rand, 'state', constantFunction( null ), noop );
+			setReadOnly( rand, 'stateLength', null );
+			setReadOnly( rand, 'byteLength', null );
+		} else {
+			setReadOnlyAccessor( rand, 'seed', getSeed );
+			setReadOnlyAccessor( rand, 'seedLength', getSeedLength );
+			setReadWriteAccessor( rand, 'state', getState, setState );
+			setReadOnlyAccessor( rand, 'stateLength', getStateLength );
+			setReadOnlyAccessor( rand, 'byteLength', getStateSize );
+		}
+		setReadOnly( rand, 'PRNG', base.PRNG );
+		setReadOnly( rand, 'assign', assign );
+		return rand;
+
+		/**
+		* Returns an array of pseudorandom values drawn from a PRNG.
+		*
+		* @private
+		* @param {NonNegativeInteger} len - output array length
+		* @param {*} param1 - PRNG parameter
+		* @param {Options} [options] - function options
+		* @param {string} [options.dtype] - output array data type
+		* @throws {TypeError} first argument must be a nonnegative integer
+		* @throws {TypeError} options argument must be an object
+		* @throws {TypeError} must provide valid options
+		* @returns {Collection} output array
+		*/
+		function rand1( len, param1, options ) {
+			if ( arguments.length < 3 ) {
+				return random.generate( len, param1 );
+			}
+			return random.generate( len, param1, options );
+		}
+
+		/**
+		* Returns an array of pseudorandom values drawn from a PRNG.
+		*
+		* @private
+		* @param {NonNegativeInteger} len - output array length
+		* @param {Options} [options] - function options
+		* @param {string} [options.dtype] - output array data type
+		* @throws {TypeError} first argument must be a nonnegative integer
+		* @throws {TypeError} options argument must be an object
+		* @throws {TypeError} must provide valid options
+		* @returns {Collection} output array
+		*/
+		function rand2( len, options ) {
+			if ( arguments.length < 2 ) {
+				return random.generate( len );
+			}
+			return random.generate( len, options );
+		}
+
+		/**
+		* Fills an array with pseudorandom values drawn from a PRNG.
+		*
+		* @private
+		* @param {*} param1 - PRNG parameter
+		* @param {Collection} out - output array
+		* @throws {TypeError} second argument must be a collection
+		* @returns {Collection} output array
+		*/
+		function assign1( param1, out ) {
+			return random.assign( param1, out );
+		}
+
+		/**
+		* Fills an array with pseudorandom values drawn from a PRNG.
+		*
+		* @private
+		* @param {Collection} out - output array
+		* @throws {TypeError} first argument must be a collection
+		* @returns {Collection} output array
+		*/
+		function assign2( out ) {
+			return random.assign( out );
+		}
+
+		/**
+		* Returns the PRNG seed.
+		*
+		* @private
+		* @returns {*} seed
+		*/
+		function getSeed() {
+			return rand.PRNG.seed;
+		}
+
+		/**
+		* Returns the PRNG seed length.
+		*
+		* @private
+		* @returns {PositiveInteger} seed length
+		*/
+		function getSeedLength() {
+			return rand.PRNG.seedLength;
+		}
+
+		/**
+		* Returns the PRNG state length.
+		*
+		* @private
+		* @returns {PositiveInteger} state length
+		*/
+		function getStateLength() {
+			return rand.PRNG.stateLength;
+		}
+
+		/**
+		* Returns the PRNG state size (in bytes).
+		*
+		* @private
+		* @returns {PositiveInteger} state size (in bytes)
+		*/
+		function getStateSize() {
+			return rand.PRNG.byteLength;
+		}
+
+		/**
+		* Returns the current pseudorandom number generator state.
+		*
+		* @private
+		* @returns {*} current state
+		*/
+		function getState() {
+			return rand.PRNG.state;
+		}
+
+		/**
+		* Sets the pseudorandom number generator state.
+		*
+		* @private
+		* @param {*} s - generator state
+		* @throws {Error} must provide a valid state
+		*/
+		function setState( s ) {
+			rand.PRNG.state = s;
+		}
+	}
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = createFactory;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary/coverage.ndjson b/random/array/tools/unary/coverage.ndjson new file mode 100644 index 000000000..b33eafbc9 --- /dev/null +++ b/random/array/tools/unary/coverage.ndjson @@ -0,0 +1 @@ +[230,304,75.6579,3,3,100,0,4,0,230,304,75.6579,"94a238318c73272acb232ac6066f596e07a8752d","2024-01-04 22:22:23 -0800"] diff --git a/random/array/tools/unary/index.html b/random/array/tools/unary/index.html new file mode 100644 index 000000000..f6338062e --- /dev/null +++ b/random/array/tools/unary/index.html @@ -0,0 +1,146 @@ + + + + + + Code coverage report for random/array/tools/unary/lib + + + + + + + + + +
+
+

All files random/array/tools/unary/lib

+
+ +
+ 75.65% + Statements + 230/304 +
+ + +
+ 100% + Branches + 3/3 +
+ + +
+ 0% + Functions + 0/4 +
+ + +
+ 75.65% + Lines + 230/304 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.js +
+
100%46/46100%1/1100%0/0100%46/46
main.js +
+
67.36%128/190100%1/10%0/367.36%128/190
validate.js +
+
82.35%56/68100%1/10%0/182.35%56/68
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary/index.js.html b/random/array/tools/unary/index.js.html new file mode 100644 index 000000000..07fa342e0 --- /dev/null +++ b/random/array/tools/unary/index.js.html @@ -0,0 +1,223 @@ + + + + + + Code coverage report for random/array/tools/unary/lib/index.js + + + + + + + + + +
+
+

All files / random/array/tools/unary/lib index.js

+
+ +
+ 100% + Statements + 46/46 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 46/46 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +471x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR 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 arrays filled with pseudorandom values drawn from a unary PRNG.
+*
+* @module @stdlib/random/array/tools/unary
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+* var Random = require( '@stdlib/random/array/tools/unary' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential, dtypes, defaultDType );
+*
+* var v = rand.generate( 10, 2.0 );
+* // returns <Float64Array>
+*/
+ 
+// MODULES //
+ 
+var main = require( './main.js' );
+ 
+ 
+// EXPORTS //
+ 
+module.exports = main;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary/main.js.html b/random/array/tools/unary/main.js.html new file mode 100644 index 000000000..5e17950ea --- /dev/null +++ b/random/array/tools/unary/main.js.html @@ -0,0 +1,655 @@ + + + + + + Code coverage report for random/array/tools/unary/lib/main.js + + + + + + + + + +
+
+

All files / random/array/tools/unary/lib main.js

+
+ +
+ 67.36% + Statements + 128/190 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/3 +
+ + +
+ 67.36% + Lines + 128/190 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +1911x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +1x +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
+var isFunction = require( '@stdlib/assert/is-function' );
+var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
+var isCollection = require( '@stdlib/assert/is-collection' );
+var contains = require( '@stdlib/array/base/assert/contains' );
+var filledBy = require( '@stdlib/array/base/filled-by' );
+var unary = require( '@stdlib/strided/base/unary' );
+var ctors = require( '@stdlib/array/ctors' );
+var format = require( '@stdlib/string/format' );
+var validate = require( './validate.js' );
+ 
+ 
+// MAIN //
+ 
+/**
+* Constructor for creating arrays filled with pseudorandom values drawn from a unary PRNG.
+*
+* @constructor
+* @param {Function} prng - unary pseudorandom value generator
+* @param {StringArray} dtypes - list of supported output data types
+* @param {string} dtype - default output data type
+* @throws {TypeError} first argument must be a function
+* @throws {TypeError} second argument must be an array of strings
+* @throws {TypeError} third argument must be a supported data type
+* @returns {Random} instance
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential, dtypes, defaultDType );
+*
+* var v = rand.generate( 10, 2.0 );
+* // returns <Float64Array>
+*/
+function Random( prng, dtypes, dtype ) {
+	if ( !( this instanceof Random ) ) {
+		return new Random( prng, dtypes, dtype );
+	}
+	if ( !isFunction( prng ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', prng ) );
+	}
+	// TODO: tighten this up by actually validating that `dtypes` contains only recognized/supported dtype strings
+	if ( !isStringArray( dtypes ) ) {
+		throw new TypeError( format( 'invalid argument. Second argument must be an array of strings. Value: `%s`.', dtypes ) );
+	}
+	// Require that the default output array data type be a member of the list of supported output array data types...
+	if ( !contains( dtypes, dtype ) ) {
+		throw new TypeError( format( 'invalid argument. Third argument must be a supported data type. Value: `%s`.', dtype ) );
+	}
+	this._prng = prng;
+	this._dtypes = dtypes;
+	this._dtype = dtype;
+	return this;
+}
+ 
+/**
+* Returns an array filled with pseudorandom values drawn from a unary PRNG.
+*
+* @name generate
+* @memberof Random.prototype
+* @type {Function}
+* @param {NonNegativeInteger} len - number of elements
+* @param {*} param1 - PRNG parameter
+* @param {Options} [options] - function options
+* @param {string} [options.dtype] - array data type
+* @throws {TypeError} first argument must be a nonnegative integer
+* @throws {TypeError} options argument must be an object
+* @throws {TypeError} must provide valid options
+* @returns {Collection} output array
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential, dtypes, defaultDType );
+*
+* var v = rand.generate( 10, 2.0 );
+* // returns <Float64Array>
+*/
+setReadOnly( Random.prototype, 'generate', function generate( len, param1, options ) {
+	var ctor;
+	var opts;
+	var prng;
+	var out;
+	var err;
+	var dt;
+	if ( !isNonNegativeInteger( len ) ) {
+		throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );
+	}
+	opts = {};
+	if ( arguments.length > 2 ) {
+		err = validate( opts, this._dtypes, options );
+		if ( err ) {
+			throw err;
+		}
+	}
+	// NOTE: we could alternatively use the PRNG factory function to create a nullary PRNG function which applies parameters for each invocation; however, this would impose a one-time cost which is likely to be rather expensive when generating small arrays. The decision made here avoids this cost, despite a small cost due to repeatedly validating parameters for each generated pseudorandom value. Additionally, the current implementation has the added benefit that it mirrors the underlying PRNG where invalid parameters result in, e.g., a return value of `NaN` (however, realization of this benefit depends on the output array being a floating-point array).
+	prng = this._prng;
+	dt = opts.dtype || this._dtype;
+	if ( dt === 'generic' ) {
+		return filledBy( len, wrapper );
+	}
+	ctor = ctors( dt );
+	out = new ctor( len );
+	unary( [ [ param1 ], out ], [ len ], [ 0, 1 ], prng );
+	return out;
+
+	/**
+	* Applies parameters to a pseudorandom value generator function.
+	*
+	* @private
+	* @returns {*} pseudorandom value
+	*/
+	function wrapper() {
+		return prng( param1 );
+	}
+});
+ 
+/**
+* Fills an array with pseudorandom values drawn from a unary PRNG.
+*
+* @name assign
+* @memberof Random.prototype
+* @type {Function}
+* @param {*} param1 - PRNG parameter
+* @param {Collection} out - output array
+* @throws {TypeError} second argument must be a collection
+* @returns {Collection} output array
+*
+* @example
+* var exponential = require( '@stdlib/random/base/exponential' );
+* var zeros = require( '@stdlib/array/zeros' );
+*
+* var dtypes = [ 'float64', 'float32', 'generic' ];
+* var defaultDType = 'float64';
+*
+* var rand = new Random( exponential, dtypes, defaultDType );
+*
+* var out = zeros( 10, 'float64' );
+* // returns <Float64Array>
+*
+* var v = rand.assign( 2.0, out );
+* // returns <Float64Array>
+*
+* var bool = ( v === out );
+* // returns true
+*/
+setReadOnly( Random.prototype, 'assign', function assign( param1, out ) {
+	if ( !isCollection( out ) ) {
+		throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', out ) );
+	}
+	// NOTE: we could alternatively use the PRNG factory function to create a nullary PRNG function which applies parameters for each invocation; however, this would impose a one-time cost which is likely to be rather expensive when filling small arrays. The decision made here avoids this cost, despite a small cost due to repeatedly validating parameters for each generated pseudorandom value. Additionally, the current implementation has the added benefit that it mirrors the underlying PRNG where invalid parameters result in, e.g., a return value of `NaN` (however, realization of this benefit depends on the output array being a floating-point array).
+	unary( [ [ param1 ], out ], [ out.length ], [ 0, 1 ], this._prng );
+	return out;
+});
+ 
+ 
+// EXPORTS //
+ 
+module.exports = Random;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/random/array/tools/unary/validate.js.html b/random/array/tools/unary/validate.js.html new file mode 100644 index 000000000..93061523b --- /dev/null +++ b/random/array/tools/unary/validate.js.html @@ -0,0 +1,289 @@ + + + + + + Code coverage report for random/array/tools/unary/lib/validate.js + + + + + + + + + +
+
+

All files / random/array/tools/unary/lib validate.js

+
+ +
+ 82.35% + Statements + 56/68 +
+ + +
+ 100% + Branches + 1/1 +
+ + +
+ 0% + Functions + 0/1 +
+ + +
+ 82.35% + Lines + 56/68 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +691x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +1x +1x +1x +1x +1x + 
/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string/format' );
+ 
+ 
+// 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 {string} [options.dtype] - output array data type
+* @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( 'invalid argument. Options argument must be an object. Value: `%s`.', 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', dtypes.join( '", "' ), opts.dtype ) );
+		}
+	}
+	return null;
+}
+ 
+ 
+// EXPORTS //
+ 
+module.exports = validate;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/types/browser.js.html b/types/browser.js.html index e302075c6..7d5f34042 100644 --- a/types/browser.js.html +++ b/types/browser.js.html @@ -154,7 +154,7 @@

All files / types/lib Code coverage generated by istanbul - at 2023-12-31T11:02:01.060Z + at 2024-01-05T06:26:45.859Z