@stdlib/random-array-invgamma 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2023 The Stdlib Authors.
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -33,7 +33,7 @@ limitations under the License.
33
33
 
34
34
  [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
35
 
36
- > Create an array containing pseudorandom numbers drawn from an [inverse gamma][@stdlib/random/base/invgamma] distribution.
36
+ > Create an array containing pseudorandom numbers drawn from a [inverse gamma][@stdlib/random/base/invgamma] distribution.
37
37
 
38
38
  <section class="installation">
39
39
 
@@ -55,7 +55,7 @@ var invgamma = require( '@stdlib/random-array-invgamma' );
55
55
 
56
56
  #### invgamma( len, alpha, beta\[, options] )
57
57
 
58
- Returns an array containing pseudorandom numbers drawn from an [inverse gamma][@stdlib/random/base/invgamma] distribution.
58
+ Returns an array containing pseudorandom numbers drawn from a [inverse gamma][@stdlib/random/base/invgamma] distribution.
59
59
 
60
60
  ```javascript
61
61
  var out = invgamma( 10, 2.0, 5.0 );
@@ -84,9 +84,32 @@ var out = invgamma( 10, 2.0, 5.0, opts );
84
84
  // returns [...]
85
85
  ```
86
86
 
87
+ #### invgamma.assign( alpha, beta, out )
88
+
89
+ Fills an array with pseudorandom numbers drawn from a [inverse gamma][@stdlib/random/base/invgamma] distribution.
90
+
91
+ ```javascript
92
+ var zeros = require( '@stdlib/array-zeros' );
93
+
94
+ var x = zeros( 10, 'float64' );
95
+ // returns <Float64Array>
96
+
97
+ var out = invgamma.assign( 2.0, 5.0, x );
98
+ // returns <Float64Array>
99
+
100
+ var bool = ( out === x );
101
+ // returns true
102
+ ```
103
+
104
+ The function has the following parameters:
105
+
106
+ - **alpha**: shape parameter.
107
+ - **beta**: scale parameter.
108
+ - **out**: output array.
109
+
87
110
  #### invgamma.factory( \[alpha, beta, ]\[options] )
88
111
 
89
- Returns a function for creating arrays containing pseudorandom numbers drawn from an [inverse gamma][@stdlib/random/base/invgamma] distribution.
112
+ Returns a function for creating arrays containing pseudorandom numbers drawn from a [inverse gamma][@stdlib/random/base/invgamma] distribution.
90
113
 
91
114
  ```javascript
92
115
  var random = invgamma.factory();
@@ -98,7 +121,7 @@ var len = out.length;
98
121
  // returns 10
99
122
  ```
100
123
 
101
- If provided `alpha` and `beta`, the returned generator returns random variates from the specified distribution.
124
+ If provided distribution parameters, the returned generator returns random variates from the specified distribution.
102
125
 
103
126
  ```javascript
104
127
  var random = invgamma.factory( 2.0, 5.0 );
@@ -110,7 +133,7 @@ out = random( 10 );
110
133
  // returns <Float64Array>
111
134
  ```
112
135
 
113
- If not provided `alpha` and `beta`, the returned generator requires that both parameters be provided at each invocation.
136
+ If not provided distribution parameters, the returned generator requires that distribution parameters be provided at each invocation.
114
137
 
115
138
  ```javascript
116
139
  var random = invgamma.factory();
@@ -354,6 +377,13 @@ logEach( '%f', x4 );
354
377
 
355
378
  <section class="related">
356
379
 
380
+ * * *
381
+
382
+ ## See Also
383
+
384
+ - <span class="package-name">[`@stdlib/random-base/invgamma`][@stdlib/random/base/invgamma]</span><span class="delimiter">: </span><span class="description">inverse gamma distributed pseudorandom numbers.</span>
385
+ - <span class="package-name">[`@stdlib/random-strided/invgamma`][@stdlib/random/strided/invgamma]</span><span class="delimiter">: </span><span class="description">fill a strided array with pseudorandom numbers drawn from an inverse gamma distribution.</span>
386
+
357
387
  </section>
358
388
 
359
389
  <!-- /.related -->
@@ -384,7 +414,7 @@ See [LICENSE][stdlib-license].
384
414
 
385
415
  ## Copyright
386
416
 
387
- Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
417
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
388
418
 
389
419
  </section>
390
420
 
@@ -397,8 +427,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
397
427
  [npm-image]: http://img.shields.io/npm/v/@stdlib/random-array-invgamma.svg
398
428
  [npm-url]: https://npmjs.org/package/@stdlib/random-array-invgamma
399
429
 
400
- [test-image]: https://github.com/stdlib-js/random-array-invgamma/actions/workflows/test.yml/badge.svg?branch=v0.1.0
401
- [test-url]: https://github.com/stdlib-js/random-array-invgamma/actions/workflows/test.yml?query=branch:v0.1.0
430
+ [test-image]: https://github.com/stdlib-js/random-array-invgamma/actions/workflows/test.yml/badge.svg?branch=v0.2.1
431
+ [test-url]: https://github.com/stdlib-js/random-array-invgamma/actions/workflows/test.yml?query=branch:v0.2.1
402
432
 
403
433
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/random-array-invgamma/main.svg
404
434
  [coverage-url]: https://codecov.io/github/stdlib-js/random-array-invgamma?branch=main
@@ -421,8 +451,11 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
421
451
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
422
452
 
423
453
  [deno-url]: https://github.com/stdlib-js/random-array-invgamma/tree/deno
454
+ [deno-readme]: https://github.com/stdlib-js/random-array-invgamma/blob/deno/README.md
424
455
  [umd-url]: https://github.com/stdlib-js/random-array-invgamma/tree/umd
456
+ [umd-readme]: https://github.com/stdlib-js/random-array-invgamma/blob/umd/README.md
425
457
  [esm-url]: https://github.com/stdlib-js/random-array-invgamma/tree/esm
458
+ [esm-readme]: https://github.com/stdlib-js/random-array-invgamma/blob/esm/README.md
426
459
  [branches-url]: https://github.com/stdlib-js/random-array-invgamma/blob/main/branches.md
427
460
 
428
461
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-array-invgamma/main/LICENSE
@@ -435,6 +468,12 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
435
468
 
436
469
  [@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64
437
470
 
471
+ <!-- <related-links> -->
472
+
473
+ [@stdlib/random/strided/invgamma]: https://www.npmjs.com/package/@stdlib/random-strided-invgamma
474
+
475
+ <!-- </related-links> -->
476
+
438
477
  </section>
439
478
 
440
479
  <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";var y=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var b=y(function(ue,H){H.exports={dtype:"float64"}});var O=y(function(se,G){
2
- var J=require('@stdlib/array-typed-real-float-dtypes/dist'),K=require('@stdlib/assert-is-plain-object/dist'),M=require('@stdlib/assert-has-own-property/dist'),N=require('@stdlib/error-tools-fmtprodmsg/dist'),w=J();w.push("generic");function Q(t,r){return K(r)?M(r,"dtype")&&(t.dtype=r.dtype,w.indexOf(t.dtype)<0)?new TypeError(N('1eB4S',"dtype",w.join('", "'),t.dtype)):null:new TypeError(N('1eB2V',r));}G.exports=Q
3
- });var R=y(function(oe,F){
4
- var S=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,d=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),l=require('@stdlib/utils-define-nonenumerable-read-only-accessor/dist'),x=require('@stdlib/utils-define-nonenumerable-read-write-accessor/dist'),U=require('@stdlib/utils-constant-function/dist'),X=require('@stdlib/utils-noop/dist'),m=require('@stdlib/random-base-invgamma/dist'),E=require('@stdlib/array-typed-real-float-ctors/dist'),T=require('@stdlib/array-base-filled-by/dist'),Z=require('@stdlib/strided-base-nullary/dist'),_=require('@stdlib/strided-base-binary/dist'),j=require('@stdlib/error-tools-fmtprodmsg/dist'),$=b(),p=O();function ee(){var t,r,v,e,a,s;if(v={dtype:$.dtype},r=arguments.length,r===0)a=m,e=P;else if(r===1){if(t=arguments[0],a=m.factory(t),s=p(v,t),s)throw s;e=P}else if(r===2)a=m.factory(arguments[0],arguments[1]),e=L;else if(r===3){if(t=arguments[2],a=m.factory(arguments[0],arguments[1],t),s=p(v,t),s)throw s;e=L}return t&&t.prng?(d(e,"seed",null),d(e,"seedLength",null),x(e,"state",U(null),X),d(e,"stateLength",null),d(e,"byteLength",null)):(l(e,"seed",B),l(e,"seedLength",D),x(e,"state",Y,k),l(e,"stateLength",I),l(e,"byteLength",W)),d(e,"PRNG",a.PRNG),e;function L(n,c){var g,f,o,i,u;if(!S(n))throw new TypeError(j('1eB2d',n));if(u={},arguments.length>1&&(o=p(u,c),o))throw o;return i=u.dtype||v.dtype,i==="generic"?T(n,a):(g=E(i),f=new g(n),Z([f],[n],[1],a),f)}function P(n,c,g,f){var o,i,u,h,q;if(!S(n))throw new TypeError(j('1eB2d',n));if(q={},arguments.length>3&&(u=p(q,f),u))throw u;if(h=q.dtype||v.dtype,h==="generic")return T(n,C);return o=E(h),i=new o(n),_([[c],[g],i],[n],[0,0,1],a),i;function C(){return a(c,g)}}function B(){return e.PRNG.seed}function D(){return e.PRNG.seedLength}function I(){return e.PRNG.stateLength}function W(){return e.PRNG.byteLength}function Y(){return e.PRNG.state}function k(n){e.PRNG.state=n}}F.exports=ee
5
- });var A=y(function(ve,V){
6
- var re=R(),te=re();V.exports=te
7
- });var ne=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),z=A(),ae=R();ne(z,"factory",ae);module.exports=z;
1
+ "use strict";var a=function(u,r){return function(){return r||u((r={exports:{}}).exports,r),r.exports}};var e=a(function(m,t){
2
+ var v=require('@stdlib/random-array-tools-binary-factory/dist'),n=require('@stdlib/array-dtypes/dist'),c=require('@stdlib/array-defaults/dist'),y=require('@stdlib/random-base-invgamma/dist'),q=n("real_floating_point_and_generic"),f=v(y,q,c.get("dtypes.real_floating_point"));t.exports=f
3
+ });var s=a(function(x,i){
4
+ var p=e(),l=p();i.exports=l
5
+ });var _=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),o=s(),d=e();_(o,"factory",d);module.exports=o;
8
6
  /** @license Apache-2.0 */
9
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/defaults.json", "../lib/validate.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["{\n\t\"dtype\": \"float64\"\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar dtypes = require( '@stdlib/array-typed-real-float-dtypes' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nDTYPES.push( 'generic' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.dtype] - output array data type\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'dtype': 'float64'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, 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 = options.dtype;\n\t\tif ( DTYPES.indexOf( opts.dtype ) < 0 ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'dtype', DTYPES.join( '\", \"' ), opts.dtype ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar noop = require( '@stdlib/utils-noop' );\nvar base = require( '@stdlib/random-base-invgamma' );\nvar ctors = require( '@stdlib/array-typed-real-float-ctors' );\nvar filledBy = require( '@stdlib/array-base-filled-by' );\nvar nullary = require( '@stdlib/strided-base-nullary' );\nvar binary = require( '@stdlib/strided-base-binary' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.json' );\nvar validate = require( './validate.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating arrays containing pseudorandom numbers drawn from an inverse gamma distribution.\n*\n* @param {PositiveNumber} [alpha] - shape parameter\n* @param {PositiveNumber} [beta] - scale parameter\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {string} [options.dtype=\"float64\"] - default data type\n* @throws {TypeError} `alpha` must be a positive number\n* @throws {TypeError} `beta` must be a positive number\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating arrays\n*\n* @example\n* var invgamma = factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = invgamma( 10 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = invgamma( 10, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\nfunction factory() {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar rand;\n\tvar prng;\n\tvar err;\n\n\topts = {\n\t\t'dtype': defaults.dtype\n\t};\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\tprng = base;\n\t\trand = invgamma2;\n\t} else if ( nargs === 1 ) {\n\t\toptions = arguments[ 0 ];\n\t\tprng = base.factory( options );\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\trand = invgamma2;\n\t} else if ( nargs === 2 ) {\n\t\tprng = base.factory( arguments[ 0 ], arguments[ 1 ] );\n\t\trand = invgamma1;\n\t} else if ( nargs === 3 ) {\n\t\toptions = arguments[ 2 ];\n\t\tprng = base.factory( arguments[ 0 ], arguments[ 1 ], options );\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\trand = invgamma1;\n\t}\n\tif ( options && options.prng ) {\n\t\tsetReadOnly( rand, 'seed', null );\n\t\tsetReadOnly( rand, 'seedLength', null );\n\t\tsetReadWriteAccessor( rand, 'state', constantFunction( null ), noop );\n\t\tsetReadOnly( rand, 'stateLength', null );\n\t\tsetReadOnly( rand, 'byteLength', null );\n\t} else {\n\t\tsetReadOnlyAccessor( rand, 'seed', getSeed );\n\t\tsetReadOnlyAccessor( rand, 'seedLength', getSeedLength );\n\t\tsetReadWriteAccessor( rand, 'state', getState, setState );\n\t\tsetReadOnlyAccessor( rand, 'stateLength', getStateLength );\n\t\tsetReadOnlyAccessor( rand, 'byteLength', getStateSize );\n\t}\n\tsetReadOnly( rand, 'PRNG', prng.PRNG );\n\treturn rand;\n\n\t/**\n\t* Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} len - array length\n\t* @param {Options} [options] - function options\n\t* @param {string} [options.dtype] - output array data type\n\t* @throws {TypeError} first argument must be a nonnegative integer\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {(Array|TypedArray)} output array\n\t*/\n\tfunction invgamma1( len, options ) {\n\t\tvar ctor;\n\t\tvar out;\n\t\tvar err;\n\t\tvar dt;\n\t\tvar o;\n\t\tif ( !isNonNegativeInteger( len ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );\n\t\t}\n\t\to = {};\n\t\tif ( arguments.length > 1 ) {\n\t\t\terr = validate( o, options );\n\t\t\tif ( err ) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\tdt = o.dtype || opts.dtype;\n\t\tif ( dt === 'generic' ) {\n\t\t\treturn filledBy( len, prng );\n\t\t}\n\t\tctor = ctors( dt );\n\t\tout = new ctor( len );\n\t\tnullary( [ out ], [ len ], [ 1 ], prng );\n\t\treturn out;\n\t}\n\n\t/**\n\t* Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} len - array length\n\t* @param {PositiveNumber} alpha - shape parameter\n\t* @param {PositiveNumber} beta - scale parameter\n\t* @param {Options} [options] - function options\n\t* @param {string} [options.dtype] - output array data type\n\t* @throws {TypeError} first argument must be a nonnegative integer\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {(Array|TypedArray)} output array\n\t*/\n\tfunction invgamma2( len, alpha, beta, options ) {\n\t\tvar ctor;\n\t\tvar out;\n\t\tvar err;\n\t\tvar dt;\n\t\tvar o;\n\t\tif ( !isNonNegativeInteger( len ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );\n\t\t}\n\t\to = {};\n\t\tif ( arguments.length > 3 ) {\n\t\t\terr = validate( o, options );\n\t\t\tif ( err ) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\t\t// NOTE: we could alternatively use the PRNG factory function to create a 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. Decision made here to avoid this cost, despite a small cost due to repeatedly validating parameters for each generated pseudorandom number. Additionally, the current implementation has the added benefit that it mirrors the underlying PRNG where invalid parameters result in a return value of `NaN`.\n\t\tdt = o.dtype || opts.dtype;\n\t\tif ( dt === 'generic' ) {\n\t\t\treturn filledBy( len, wrapper );\n\t\t}\n\t\tctor = ctors( dt );\n\t\tout = new ctor( len );\n\t\tbinary( [ [ alpha ], [ beta ], out ], [ len ], [ 0, 0, 1 ], prng );\n\t\treturn out;\n\n\t\t/**\n\t\t* Applies parameters to a pseudorandom number generator function.\n\t\t*\n\t\t* @private\n\t\t* @returns {number} pseudorandom number\n\t\t*/\n\t\tfunction wrapper() {\n\t\t\treturn prng( alpha, beta );\n\t\t}\n\t}\n\n\t/**\n\t* Returns the PRNG seed.\n\t*\n\t* @private\n\t* @returns {PRNGSeedMT19937} seed\n\t*/\n\tfunction getSeed() {\n\t\treturn rand.PRNG.seed;\n\t}\n\n\t/**\n\t* Returns the PRNG seed length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} seed length\n\t*/\n\tfunction getSeedLength() {\n\t\treturn rand.PRNG.seedLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state length.\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state length\n\t*/\n\tfunction getStateLength() {\n\t\treturn rand.PRNG.stateLength;\n\t}\n\n\t/**\n\t* Returns the PRNG state size (in bytes).\n\t*\n\t* @private\n\t* @returns {PositiveInteger} state size (in bytes)\n\t*/\n\tfunction getStateSize() {\n\t\treturn rand.PRNG.byteLength;\n\t}\n\n\t/**\n\t* Returns the current pseudorandom number generator state.\n\t*\n\t* @private\n\t* @returns {PRNGStateMT19937} current state\n\t*/\n\tfunction getState() {\n\t\treturn rand.PRNG.state;\n\t}\n\n\t/**\n\t* Sets the pseudorandom number generator state.\n\t*\n\t* @private\n\t* @param {PRNGStateMT19937} s - generator state\n\t* @throws {Error} must provide a valid state\n\t*/\n\tfunction setState( s ) {\n\t\trand.PRNG.state = s;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).\n*\n* @name invgamma\n* @type {Function}\n* @param {NonNegativeInteger} len - array length\n* @param {PositiveNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - scale parameter\n* @param {Options} [options] - options\n* @param {string} [options.dtype=\"float64\"] - output array data type\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {(Array|TypedArray)} output array\n*\n* @example\n* var arr = invgamma( 10, 2.0, 5.0 );\n* // returns <Float64Array>\n*\n* @example\n* var arr = invgamma( 10, 2.0, 5.0, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\nvar invgamma = factory();\n\n\n// EXPORTS //\n\nmodule.exports = invgamma;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).\n*\n* @module @stdlib/random-array-invgamma\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var arr = invgamma( 10, 2.0, 5.0 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var arr = invgamma( 10, 2.0, 5.0, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var rand = invgamma.factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = rand( 10 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var rand = invgamma.factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = rand( 10, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"factory\": \"main.factory\" }\n"],
5
- "mappings": "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",
6
- "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "dtypes", "isObject", "hasOwnProp", "format", "DTYPES", "validate", "opts", "options", "require_factory", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "setReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "constantFunction", "noop", "base", "ctors", "filledBy", "nullary", "binary", "format", "defaults", "validate", "factory", "options", "nargs", "opts", "rand", "prng", "err", "invgamma2", "invgamma1", "getSeed", "getSeedLength", "getState", "setState", "getStateLength", "getStateSize", "len", "ctor", "out", "dt", "o", "alpha", "beta", "wrapper", "s", "require_main", "__commonJSMin", "exports", "module", "factory", "invgamma", "setReadOnly", "main", "factory"]
3
+ "sources": ["../lib/factory.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar binaryFactory = require( '@stdlib/random-array-tools-binary-factory' );\nvar dtypes = require( '@stdlib/array-dtypes' );\nvar defaults = require( '@stdlib/array-defaults' );\nvar base = require( '@stdlib/random-base-invgamma' );\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes( 'real_floating_point_and_generic' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating arrays containing pseudorandom numbers drawn from an inverse gamma distribution.\n*\n* @name factory\n* @type {Function}\n* @param {PositiveNumber} [alpha] - shape parameter\n* @param {PositiveNumber} [beta] - scale parameter\n* @param {Options} [options] - function options\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {string} [options.dtype=\"float64\"] - default data type\n* @throws {TypeError} `alpha` must be a positive number\n* @throws {TypeError} `beta` must be a positive number\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {Function} function for creating arrays\n*\n* @example\n* var invgamma = factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = invgamma( 10 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = invgamma( 10, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\nvar factory = binaryFactory( base, DTYPES, defaults.get( 'dtypes.real_floating_point' ) );\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.\n*\n* @name invgamma\n* @type {Function}\n* @param {NonNegativeInteger} len - array length\n* @param {PositiveNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - scale parameter\n* @param {Options} [options] - options\n* @param {string} [options.dtype=\"float64\"] - output array data type\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {(Array|TypedArray)} output array\n*\n* @example\n* var arr = invgamma( 10, 2.0, 5.0 );\n* // returns <Float64Array>\n*\n* @example\n* var arr = invgamma( 10, 2.0, 5.0, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\nvar invgamma = factory();\n\n\n// EXPORTS //\n\nmodule.exports = invgamma;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an array containing pseudorandom numbers drawn from an inverse gamma distribution.\n*\n* @module @stdlib/random-array-invgamma\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var arr = invgamma( 10, 2.0, 5.0 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var arr = invgamma( 10, 2.0, 5.0, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var rand = invgamma.factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = rand( 10 );\n* // returns <Float64Array>\n*\n* @example\n* var invgamma = require( '@stdlib/random-array-invgamma' );\n*\n* var rand = invgamma.factory( 2.0, 5.0 );\n* // returns <Function>\n*\n* var arr = rand( 10, {\n* 'dtype': 'generic'\n* });\n* // returns [...]\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"factory\": \"main.factory\", \"assign\": \"main.assign\" }\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,2CAA4C,EACrEC,EAAS,QAAS,sBAAuB,EACzCC,EAAW,QAAS,wBAAyB,EAC7CC,EAAO,QAAS,8BAA+B,EAK/CC,EAASH,EAAQ,iCAAkC,EAyCnDI,EAAUL,EAAeG,EAAMC,EAAQF,EAAS,IAAK,4BAA6B,CAAE,EAKxFH,EAAO,QAAUM,IC5EjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IA8BVC,EAAWD,EAAQ,EAKvBD,EAAO,QAAUE,ICKjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
+ "names": ["require_factory", "__commonJSMin", "exports", "module", "binaryFactory", "dtypes", "defaults", "base", "DTYPES", "factory", "require_main", "__commonJSMin", "exports", "module", "factory", "invgamma", "setReadOnly", "main", "factory"]
7
7
  }
@@ -20,14 +20,9 @@
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { FloatDataType, FloatTypedArray } from '@stdlib/types/array';
23
+ import { RealFloatingPointAndGenericDataType as DataType, FloatTypedArray } from '@stdlib/types/array';
24
24
  import * as random from '@stdlib/types/random';
25
25
 
26
- /**
27
- * Supported data types.
28
- */
29
- type DataType = FloatDataType | 'generic';
30
-
31
26
  /**
32
27
  * Output array.
33
28
  */
@@ -118,13 +113,21 @@ interface PRNG {
118
113
  */
119
114
  interface UnaryFunction extends PRNG {
120
115
  /**
121
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
116
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.
122
117
  *
123
118
  * @param len - array length
124
119
  * @param options - function options
125
120
  * @returns output array
126
121
  */
127
122
  ( len: number, options?: Options ): RandomArray;
123
+
124
+ /**
125
+ * Fills an array with pseudorandom numbers drawn from an inverse gamma distribution.
126
+ *
127
+ * @param out - output array
128
+ * @returns output array
129
+ */
130
+ assign( out: RandomArray ): RandomArray;
128
131
  }
129
132
 
130
133
  /**
@@ -132,7 +135,7 @@ interface UnaryFunction extends PRNG {
132
135
  */
133
136
  interface TernaryFunction extends PRNG {
134
137
  /**
135
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
138
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.
136
139
  *
137
140
  * @param len - array length
138
141
  * @param alpha - shape parameter
@@ -140,7 +143,17 @@ interface TernaryFunction extends PRNG {
140
143
  * @param options - function options
141
144
  * @returns output array
142
145
  */
143
- ( len: number, alpha: number, beta: number, options?: Options ): RandomArray; // tslint:disable-line: max-line-length
146
+ ( len: number, alpha: number, beta: number, options?: Options ): RandomArray;
147
+
148
+ /**
149
+ * Fills an array with pseudorandom numbers drawn from an inverse gamma distribution.
150
+ *
151
+ * @param alpha - shape parameter
152
+ * @param beta - scale parameter
153
+ * @param out - output array
154
+ * @returns output array
155
+ */
156
+ assign( alpha: number, beta: number, out: RandomArray ): RandomArray;
144
157
  }
145
158
 
146
159
  /**
@@ -148,7 +161,7 @@ interface TernaryFunction extends PRNG {
148
161
  */
149
162
  interface Random extends PRNG {
150
163
  /**
151
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
164
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.
152
165
  *
153
166
  * @param len - array length
154
167
  * @param alpha - shape parameter
@@ -160,20 +173,40 @@ interface Random extends PRNG {
160
173
  * var out = invgamma( 10, 2.0, 5.0 );
161
174
  * // returns <Float64Array>
162
175
  */
163
- ( len: number, alpha: number, beta: number, options?: Options ): RandomArray; // tslint:disable-line: max-line-length
176
+ ( len: number, alpha: number, beta: number, options?: Options ): RandomArray;
177
+
178
+ /**
179
+ * Fills an array with pseudorandom numbers drawn from an inverse gamma distribution.
180
+ *
181
+ * @param alpha - shape parameter
182
+ * @param beta - scale parameter
183
+ * @param out - output array
184
+ * @returns output array
185
+ *
186
+ * @example
187
+ * var zeros = require( '@stdlib/array-zeros' );
188
+ *
189
+ * var x = zeros( 10, 'float64' );
190
+ * // returns <Float64Array>
191
+ *
192
+ * var out = invgamma( 2.0, 5.0, out );
193
+ * // returns <Float64Array>
194
+ *
195
+ * var bool = ( out === x );
196
+ * // returns true
197
+ */
198
+ assign( alpha: number, beta: number, out: RandomArray ): RandomArray;
164
199
 
165
200
  /**
166
201
  * Returns a function for creating arrays containing pseudorandom numbers drawn from an inverse gamma distribution.
167
202
  *
168
203
  * ## Notes
169
204
  *
170
- * - When provided `alpha` and `beta`, the returned function returns random variates drawn from the specified distribution.
205
+ * - When provided distribution parameters, the returned function returns random variates drawn from the specified distribution.
171
206
  *
172
207
  * @param alpha - shape parameter
173
208
  * @param beta - scale parameter
174
209
  * @param options - function options
175
- * @throws `alpha` must be a positive number
176
- * @throws `beta` must be a positive number
177
210
  * @throws must provide a valid state
178
211
  * @returns function for creating arrays
179
212
  *
@@ -190,27 +223,27 @@ interface Random extends PRNG {
190
223
  * var out = random( 10 );
191
224
  * // returns <Float64Array>
192
225
  */
193
- factory( alpha: number, beta: number, options?: FactoryOptions ): UnaryFunction; // tslint:disable-line: max-line-length
226
+ factory( alpha: number, beta: number, options?: FactoryOptions ): UnaryFunction;
194
227
 
195
228
  /**
196
229
  * Returns a function for creating arrays containing pseudorandom numbers drawn from an inverse gamma distribution.
197
230
  *
198
231
  * ## Notes
199
232
  *
200
- * - When not provided `alpha` and `beta`, the returned function requires that both `alpha` and `beta` be provided at each invocation.
233
+ * - When not provided distribution parameters, the returned function requires that distribution parameters be provided at each invocation.
201
234
  *
202
235
  * @param options - function options
203
236
  * @throws must provide a valid state
204
237
  * @returns function for creating arrays
205
238
  *
206
239
  * @example
207
- * var random = beta.factory();
240
+ * var random = invgamma.factory();
208
241
  *
209
242
  * var out = random( 10, 2.0, 5.0 );
210
243
  * // returns <Float64Array>
211
244
  *
212
245
  * @example
213
- * var random = beta.factory({
246
+ * var random = invgamma.factory({
214
247
  * 'seed': 297
215
248
  * });
216
249
  * var out = random( 10, 2.0, 5.0 );
@@ -220,7 +253,7 @@ interface Random extends PRNG {
220
253
  }
221
254
 
222
255
  /**
223
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
256
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.
224
257
  *
225
258
  * @param len - array length
226
259
  * @param alpha - shape parameter
package/lib/factory.js CHANGED
@@ -20,20 +20,15 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;
24
- var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
25
- var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );
26
- var setReadWriteAccessor = require( '@stdlib/utils-define-nonenumerable-read-write-accessor' );
27
- var constantFunction = require( '@stdlib/utils-constant-function' );
28
- var noop = require( '@stdlib/utils-noop' );
23
+ var binaryFactory = require( '@stdlib/random-array-tools-binary-factory' );
24
+ var dtypes = require( '@stdlib/array-dtypes' );
25
+ var defaults = require( '@stdlib/array-defaults' );
29
26
  var base = require( '@stdlib/random-base-invgamma' );
30
- var ctors = require( '@stdlib/array-typed-real-float-ctors' );
31
- var filledBy = require( '@stdlib/array-base-filled-by' );
32
- var nullary = require( '@stdlib/strided-base-nullary' );
33
- var binary = require( '@stdlib/strided-base-binary' );
34
- var format = require( '@stdlib/string-format' );
35
- var defaults = require( './defaults.json' );
36
- var validate = require( './validate.js' );
27
+
28
+
29
+ // VARIABLES //
30
+
31
+ var DTYPES = dtypes( 'real_floating_point_and_generic' );
37
32
 
38
33
 
39
34
  // MAIN //
@@ -41,6 +36,8 @@ var validate = require( './validate.js' );
41
36
  /**
42
37
  * Returns a function for creating arrays containing pseudorandom numbers drawn from an inverse gamma distribution.
43
38
  *
39
+ * @name factory
40
+ * @type {Function}
44
41
  * @param {PositiveNumber} [alpha] - shape parameter
45
42
  * @param {PositiveNumber} [beta] - scale parameter
46
43
  * @param {Options} [options] - function options
@@ -72,208 +69,7 @@ var validate = require( './validate.js' );
72
69
  * });
73
70
  * // returns [...]
74
71
  */
75
- function factory() {
76
- var options;
77
- var nargs;
78
- var opts;
79
- var rand;
80
- var prng;
81
- var err;
82
-
83
- opts = {
84
- 'dtype': defaults.dtype
85
- };
86
-
87
- nargs = arguments.length;
88
- if ( nargs === 0 ) {
89
- prng = base;
90
- rand = invgamma2;
91
- } else if ( nargs === 1 ) {
92
- options = arguments[ 0 ];
93
- prng = base.factory( options );
94
- err = validate( opts, options );
95
- if ( err ) {
96
- throw err;
97
- }
98
- rand = invgamma2;
99
- } else if ( nargs === 2 ) {
100
- prng = base.factory( arguments[ 0 ], arguments[ 1 ] );
101
- rand = invgamma1;
102
- } else if ( nargs === 3 ) {
103
- options = arguments[ 2 ];
104
- prng = base.factory( arguments[ 0 ], arguments[ 1 ], options );
105
- err = validate( opts, options );
106
- if ( err ) {
107
- throw err;
108
- }
109
- rand = invgamma1;
110
- }
111
- if ( options && options.prng ) {
112
- setReadOnly( rand, 'seed', null );
113
- setReadOnly( rand, 'seedLength', null );
114
- setReadWriteAccessor( rand, 'state', constantFunction( null ), noop );
115
- setReadOnly( rand, 'stateLength', null );
116
- setReadOnly( rand, 'byteLength', null );
117
- } else {
118
- setReadOnlyAccessor( rand, 'seed', getSeed );
119
- setReadOnlyAccessor( rand, 'seedLength', getSeedLength );
120
- setReadWriteAccessor( rand, 'state', getState, setState );
121
- setReadOnlyAccessor( rand, 'stateLength', getStateLength );
122
- setReadOnlyAccessor( rand, 'byteLength', getStateSize );
123
- }
124
- setReadOnly( rand, 'PRNG', prng.PRNG );
125
- return rand;
126
-
127
- /**
128
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
129
- *
130
- * @private
131
- * @param {NonNegativeInteger} len - array length
132
- * @param {Options} [options] - function options
133
- * @param {string} [options.dtype] - output array data type
134
- * @throws {TypeError} first argument must be a nonnegative integer
135
- * @throws {TypeError} options argument must be an object
136
- * @throws {TypeError} must provide valid options
137
- * @returns {(Array|TypedArray)} output array
138
- */
139
- function invgamma1( len, options ) {
140
- var ctor;
141
- var out;
142
- var err;
143
- var dt;
144
- var o;
145
- if ( !isNonNegativeInteger( len ) ) {
146
- throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );
147
- }
148
- o = {};
149
- if ( arguments.length > 1 ) {
150
- err = validate( o, options );
151
- if ( err ) {
152
- throw err;
153
- }
154
- }
155
- dt = o.dtype || opts.dtype;
156
- if ( dt === 'generic' ) {
157
- return filledBy( len, prng );
158
- }
159
- ctor = ctors( dt );
160
- out = new ctor( len );
161
- nullary( [ out ], [ len ], [ 1 ], prng );
162
- return out;
163
- }
164
-
165
- /**
166
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
167
- *
168
- * @private
169
- * @param {NonNegativeInteger} len - array length
170
- * @param {PositiveNumber} alpha - shape parameter
171
- * @param {PositiveNumber} beta - scale parameter
172
- * @param {Options} [options] - function options
173
- * @param {string} [options.dtype] - output array data type
174
- * @throws {TypeError} first argument must be a nonnegative integer
175
- * @throws {TypeError} options argument must be an object
176
- * @throws {TypeError} must provide valid options
177
- * @returns {(Array|TypedArray)} output array
178
- */
179
- function invgamma2( len, alpha, beta, options ) {
180
- var ctor;
181
- var out;
182
- var err;
183
- var dt;
184
- var o;
185
- if ( !isNonNegativeInteger( len ) ) {
186
- throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', len ) );
187
- }
188
- o = {};
189
- if ( arguments.length > 3 ) {
190
- err = validate( o, options );
191
- if ( err ) {
192
- throw err;
193
- }
194
- }
195
- // NOTE: we could alternatively use the PRNG factory function to create a 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. Decision made here to avoid this cost, despite a small cost due to repeatedly validating parameters for each generated pseudorandom number. Additionally, the current implementation has the added benefit that it mirrors the underlying PRNG where invalid parameters result in a return value of `NaN`.
196
- dt = o.dtype || opts.dtype;
197
- if ( dt === 'generic' ) {
198
- return filledBy( len, wrapper );
199
- }
200
- ctor = ctors( dt );
201
- out = new ctor( len );
202
- binary( [ [ alpha ], [ beta ], out ], [ len ], [ 0, 0, 1 ], prng );
203
- return out;
204
-
205
- /**
206
- * Applies parameters to a pseudorandom number generator function.
207
- *
208
- * @private
209
- * @returns {number} pseudorandom number
210
- */
211
- function wrapper() {
212
- return prng( alpha, beta );
213
- }
214
- }
215
-
216
- /**
217
- * Returns the PRNG seed.
218
- *
219
- * @private
220
- * @returns {PRNGSeedMT19937} seed
221
- */
222
- function getSeed() {
223
- return rand.PRNG.seed;
224
- }
225
-
226
- /**
227
- * Returns the PRNG seed length.
228
- *
229
- * @private
230
- * @returns {PositiveInteger} seed length
231
- */
232
- function getSeedLength() {
233
- return rand.PRNG.seedLength;
234
- }
235
-
236
- /**
237
- * Returns the PRNG state length.
238
- *
239
- * @private
240
- * @returns {PositiveInteger} state length
241
- */
242
- function getStateLength() {
243
- return rand.PRNG.stateLength;
244
- }
245
-
246
- /**
247
- * Returns the PRNG state size (in bytes).
248
- *
249
- * @private
250
- * @returns {PositiveInteger} state size (in bytes)
251
- */
252
- function getStateSize() {
253
- return rand.PRNG.byteLength;
254
- }
255
-
256
- /**
257
- * Returns the current pseudorandom number generator state.
258
- *
259
- * @private
260
- * @returns {PRNGStateMT19937} current state
261
- */
262
- function getState() {
263
- return rand.PRNG.state;
264
- }
265
-
266
- /**
267
- * Sets the pseudorandom number generator state.
268
- *
269
- * @private
270
- * @param {PRNGStateMT19937} s - generator state
271
- * @throws {Error} must provide a valid state
272
- */
273
- function setState( s ) {
274
- rand.PRNG.state = s;
275
- }
276
- }
72
+ var factory = binaryFactory( base, DTYPES, defaults.get( 'dtypes.real_floating_point' ) );
277
73
 
278
74
 
279
75
  // EXPORTS //
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  'use strict';
20
20
 
21
21
  /**
22
- * Create an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
22
+ * Create an array containing pseudorandom numbers drawn from an inverse gamma distribution.
23
23
  *
24
24
  * @module @stdlib/random-array-invgamma
25
25
  *
@@ -74,4 +74,4 @@ setReadOnly( main, 'factory', factory );
74
74
 
75
75
  module.exports = main;
76
76
 
77
- // exports: { "factory": "main.factory" }
77
+ // exports: { "factory": "main.factory", "assign": "main.assign" }
package/lib/main.js CHANGED
@@ -26,7 +26,7 @@ var factory = require( './factory.js' );
26
26
  // MAIN //
27
27
 
28
28
  /**
29
- * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
29
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution.
30
30
  *
31
31
  * @name invgamma
32
32
  * @type {Function}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/random-array-invgamma",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Create an array containing pseudorandom numbers drawn from an inverse gamma distribution.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,19 +15,12 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "directories": {
18
- "benchmark": "./benchmark",
19
18
  "doc": "./docs",
20
- "example": "./examples",
21
19
  "lib": "./lib",
22
- "test": "./test"
20
+ "dist": "./dist"
23
21
  },
24
22
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
23
+ "scripts": {},
31
24
  "homepage": "https://stdlib.io",
32
25
  "repository": {
33
26
  "type": "git",
@@ -37,40 +30,13 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/array-base-filled-by": "^0.1.0",
41
- "@stdlib/array-typed-real-float-ctors": "^0.1.0",
42
- "@stdlib/array-typed-real-float-dtypes": "^0.1.0",
43
- "@stdlib/assert-has-own-property": "^0.1.0",
44
- "@stdlib/assert-is-nonnegative-integer": "^0.1.0",
45
- "@stdlib/assert-is-plain-object": "^0.1.0",
46
- "@stdlib/random-base-invgamma": "^0.1.0",
47
- "@stdlib/strided-base-binary": "^0.1.0",
48
- "@stdlib/strided-base-nullary": "^0.1.0",
49
- "@stdlib/string-format": "^0.1.0",
50
- "@stdlib/types": "^0.1.0",
51
- "@stdlib/utils-constant-function": "^0.1.0",
52
- "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0",
53
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0",
54
- "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.0",
55
- "@stdlib/utils-noop": "^0.1.0",
56
- "@stdlib/error-tools-fmtprodmsg": "^0.1.0"
57
- },
58
- "devDependencies": {
59
- "@stdlib/array-float32": "^0.1.0",
60
- "@stdlib/array-float64": "^0.1.0",
61
- "@stdlib/array-uint32": "^0.1.0",
62
- "@stdlib/assert-is-uint32array": "^0.1.0",
63
- "@stdlib/bench": "^0.1.0",
64
- "@stdlib/console-log-each": "^0.1.0",
65
- "@stdlib/constants-uint32-max": "^0.1.0",
66
- "@stdlib/math-base-assert-is-nan": "^0.1.0",
67
- "@stdlib/math-base-assert-is-nanf": "^0.1.0",
68
- "@stdlib/math-base-special-pow": "^0.1.0",
69
- "@stdlib/random-base-minstd": "^0.1.0",
70
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
71
- "istanbul": "^0.4.1",
72
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
33
+ "@stdlib/array-defaults": "^0.2.1",
34
+ "@stdlib/array-dtypes": "^0.2.1",
35
+ "@stdlib/random-array-tools-binary-factory": "^0.2.1",
36
+ "@stdlib/random-base-invgamma": "^0.2.1",
37
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1"
73
38
  },
39
+ "devDependencies": {},
74
40
  "engines": {
75
41
  "node": ">=0.10.0",
76
42
  "npm": ">2.7.0"
package/CITATION.cff DELETED
@@ -1,30 +0,0 @@
1
- cff-version: 1.2.0
2
- title: stdlib
3
- message: >-
4
- If you use this software, please cite it using the
5
- metadata from this file.
6
-
7
- type: software
8
-
9
- authors:
10
- - name: The Stdlib Authors
11
- url: https://github.com/stdlib-js/stdlib/graphs/contributors
12
-
13
- repository-code: https://github.com/stdlib-js/stdlib
14
- url: https://stdlib.io
15
-
16
- abstract: |
17
- Standard library for JavaScript and Node.js.
18
-
19
- keywords:
20
- - JavaScript
21
- - Node.js
22
- - TypeScript
23
- - standard library
24
- - scientific computing
25
- - numerical computing
26
- - statistical computing
27
-
28
- license: Apache-2.0 AND BSL-1.0
29
-
30
- date-released: 2016
package/lib/defaults.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "dtype": "float64"
3
- }
package/lib/validate.js DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2023 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- 'use strict';
20
-
21
- // MODULES //
22
-
23
- var dtypes = require( '@stdlib/array-typed-real-float-dtypes' );
24
- var isObject = require( '@stdlib/assert-is-plain-object' );
25
- var hasOwnProp = require( '@stdlib/assert-has-own-property' );
26
- var format = require( '@stdlib/string-format' );
27
-
28
-
29
- // VARIABLES //
30
-
31
- var DTYPES = dtypes();
32
- DTYPES.push( 'generic' );
33
-
34
-
35
- // MAIN //
36
-
37
- /**
38
- * Validates function options.
39
- *
40
- * @private
41
- * @param {Object} opts - destination object
42
- * @param {Options} options - function options
43
- * @param {string} [options.dtype] - output array data type
44
- * @returns {(Error|null)} null or an error object
45
- *
46
- * @example
47
- * var opts = {};
48
- * var options = {
49
- * 'dtype': 'float64'
50
- * };
51
- * var err = validate( opts, options );
52
- * if ( err ) {
53
- * throw err;
54
- * }
55
- */
56
- function validate( opts, options ) {
57
- if ( !isObject( options ) ) {
58
- return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
59
- }
60
- if ( hasOwnProp( options, 'dtype' ) ) {
61
- opts.dtype = options.dtype;
62
- if ( DTYPES.indexOf( opts.dtype ) < 0 ) {
63
- return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', DTYPES.join( '", "' ), opts.dtype ) );
64
- }
65
- }
66
- return null;
67
- }
68
-
69
-
70
- // EXPORTS //
71
-
72
- module.exports = validate;