@stdlib/random-array-invgamma 0.1.0

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/lib/main.js ADDED
@@ -0,0 +1,58 @@
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 factory = require( './factory.js' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Returns an array containing pseudorandom numbers drawn from an inverse gamma distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
30
+ *
31
+ * @name invgamma
32
+ * @type {Function}
33
+ * @param {NonNegativeInteger} len - array length
34
+ * @param {PositiveNumber} alpha - shape parameter
35
+ * @param {PositiveNumber} beta - scale parameter
36
+ * @param {Options} [options] - options
37
+ * @param {string} [options.dtype="float64"] - output array data type
38
+ * @throws {TypeError} first argument must be a nonnegative integer
39
+ * @throws {TypeError} options argument must be an object
40
+ * @throws {TypeError} must provide valid options
41
+ * @returns {(Array|TypedArray)} output array
42
+ *
43
+ * @example
44
+ * var arr = invgamma( 10, 2.0, 5.0 );
45
+ * // returns <Float64Array>
46
+ *
47
+ * @example
48
+ * var arr = invgamma( 10, 2.0, 5.0, {
49
+ * 'dtype': 'generic'
50
+ * });
51
+ * // returns [...]
52
+ */
53
+ var invgamma = factory();
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ module.exports = invgamma;
@@ -0,0 +1,72 @@
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;
package/package.json ADDED
@@ -0,0 +1,115 @@
1
+ {
2
+ "name": "@stdlib/random-array-invgamma",
3
+ "version": "0.1.0",
4
+ "description": "Create an array containing pseudorandom numbers drawn from an inverse gamma distribution.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {
26
+ "test": "make test",
27
+ "test-cov": "make test-cov",
28
+ "examples": "make examples",
29
+ "benchmark": "make benchmark"
30
+ },
31
+ "homepage": "https://stdlib.io",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git://github.com/stdlib-js/random-array-invgamma.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/stdlib-js/stdlib/issues"
38
+ },
39
+ "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"
73
+ },
74
+ "engines": {
75
+ "node": ">=0.10.0",
76
+ "npm": ">2.7.0"
77
+ },
78
+ "os": [
79
+ "aix",
80
+ "darwin",
81
+ "freebsd",
82
+ "linux",
83
+ "macos",
84
+ "openbsd",
85
+ "sunos",
86
+ "win32",
87
+ "windows"
88
+ ],
89
+ "keywords": [
90
+ "stdlib",
91
+ "stdmath",
92
+ "mathematics",
93
+ "math",
94
+ "statistics",
95
+ "stats",
96
+ "prng",
97
+ "rng",
98
+ "pseudorandom",
99
+ "random",
100
+ "rand",
101
+ "inverse",
102
+ "gamma",
103
+ "inverse-gamma",
104
+ "continuous",
105
+ "generator",
106
+ "seed",
107
+ "seedable",
108
+ "array",
109
+ "vector"
110
+ ],
111
+ "funding": {
112
+ "type": "opencollective",
113
+ "url": "https://opencollective.com/stdlib"
114
+ }
115
+ }